parent
a70dae980a
commit
07504ad3f2
Binary file not shown.
@ -1,39 +1,10 @@
|
|||||||
import requests
|
from Util.ALiYunUtil import ALiYunUtil
|
||||||
from Config.Config import MODEL_API_KEY, MODEL_NAME
|
|
||||||
|
|
||||||
class QWenClient:
|
|
||||||
def __init__(self):
|
|
||||||
self.api_key = MODEL_API_KEY
|
|
||||||
self.model_name = MODEL_NAME
|
|
||||||
self.base_url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation"
|
|
||||||
|
|
||||||
def generate(self, prompt):
|
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer {self.api_key}",
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"model": self.model_name,
|
|
||||||
"input": {
|
|
||||||
"messages": [
|
|
||||||
{"role": "user", "content": prompt}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response = requests.post(self.base_url, json=payload, headers=headers)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = QWenClient()
|
ali_util = ALiYunUtil()
|
||||||
while True:
|
while True:
|
||||||
prompt = input("请输入问题(输入q退出): ")
|
prompt = input("请输入问题(输入q退出): ")
|
||||||
if prompt.lower() == 'q':
|
if prompt.lower() == 'q':
|
||||||
break
|
break
|
||||||
try:
|
answer = ali_util.chat(prompt)
|
||||||
result = client.generate(prompt)
|
print("回答:", answer)
|
||||||
print("回答:", result['output']['text'])
|
|
||||||
except Exception as e:
|
|
||||||
print(f"发生错误: {str(e)}")
|
|
Binary file not shown.
Loading…
Reference in new issue