zhaokeyao1
commited on
Commit
·
1d80acf
1
Parent(s):
5eb30f2
Update app
Browse files
app.py
CHANGED
|
@@ -8,13 +8,42 @@ from openai import OpenAI
|
|
| 8 |
|
| 9 |
class ChatgptAPI:
|
| 10 |
def __init__(self, ):
|
|
|
|
| 11 |
self.client = OpenAI(
|
| 12 |
api_key = os.environ.get("OPENAI_API_KEY"),
|
| 13 |
base_url = "https://api.moonshot.cn/v1",
|
| 14 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def get_summary(self, file_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
file_object = self.client.files.create(file=Path(file_path), purpose="file-extract")
|
| 19 |
file_content = self.client.files.content(file_id=file_object.id).text
|
| 20 |
messages = [
|
|
@@ -35,7 +64,7 @@ class ChatgptAPI:
|
|
| 35 |
)
|
| 36 |
message=completion.choices[0].message.content
|
| 37 |
return message
|
| 38 |
-
|
| 39 |
|
| 40 |
def get_single_round_completion(self, file_path, prompt, conversation):
|
| 41 |
conversation.append_question(prompt)
|
|
|
|
| 8 |
|
| 9 |
class ChatgptAPI:
|
| 10 |
def __init__(self, ):
|
| 11 |
+
'''
|
| 12 |
self.client = OpenAI(
|
| 13 |
api_key = os.environ.get("OPENAI_API_KEY"),
|
| 14 |
base_url = "https://api.moonshot.cn/v1",
|
| 15 |
)
|
| 16 |
+
'''
|
| 17 |
+
self.client=OpenAI(
|
| 18 |
+
api_key="sk-99f10c5ab8da406b90dd389e04218d09", # �滻����ʵDashScope��API_KEY
|
| 19 |
+
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # ��дDashScopebase_url
|
| 20 |
+
)
|
| 21 |
|
| 22 |
|
| 23 |
def get_summary(self, file_path):
|
| 24 |
+
file = self.client.files.create(file=Path(file_path), purpose="file-extract")
|
| 25 |
+
completion = client.chat.completions.create(
|
| 26 |
+
model="qwen-long",
|
| 27 |
+
messages=[
|
| 28 |
+
{
|
| 29 |
+
'role': 'system',
|
| 30 |
+
'content': 'You are a helpful assistant.'
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
'role': 'system',
|
| 34 |
+
'content': f'fileid://{file.id}'
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
'role': 'user',
|
| 38 |
+
'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�������Ҫ������ѯʦ�Ļػ�����Ϊ�������Dz���ȷ�ġ�step by step������²��裺\n ����1-���Ķ����ϴ����ı��ļ���ȫ�����ݣ�ֱ�����һ���ַ� \n ����2-��ȫ����ժȡ�����ߵġ��ؼ��Է��ԡ�����Ҫ��ժ¼�ı�ǰ�벿�ֵķ��ԣ�����ѡ����������Ҫ�����۵�3-4������¼���Խ������һ����ѯʦ����Ļظ�����Ϊ����ѯʦ�Ļظ��� \n ����3-��Թؼ��Է��ԣ��������ʵġ������ػ����ݡ� \n ����4-�Աȡ������ػ����ݡ��͡���ѯʦ�Ļظ���������ÿ���Ӧ��֣�0��Ϊ�붽���ػ�������ȫ��һ�£�10���붽���ػ�������ȫһ�£� \n ����5-����4����ִ�в��������������json��ʽ����� [{"key_num" : "n", "visiter" : "����������", "superior" : "�����ػ���������", "adviser" : "��ѯʦ�Ļظ�����",��"score" : "x/10", "reason" : "��ԭ������"}]'
|
| 39 |
+
}
|
| 40 |
+
],
|
| 41 |
+
stream=False
|
| 42 |
+
)
|
| 43 |
+
message=completion.choices[0].message.dict()['content']
|
| 44 |
+
return message
|
| 45 |
+
|
| 46 |
+
'''
|
| 47 |
file_object = self.client.files.create(file=Path(file_path), purpose="file-extract")
|
| 48 |
file_content = self.client.files.content(file_id=file_object.id).text
|
| 49 |
messages = [
|
|
|
|
| 64 |
)
|
| 65 |
message=completion.choices[0].message.content
|
| 66 |
return message
|
| 67 |
+
'''
|
| 68 |
|
| 69 |
def get_single_round_completion(self, file_path, prompt, conversation):
|
| 70 |
conversation.append_question(prompt)
|