several_clients
Browse files
app.py
CHANGED
@@ -73,37 +73,48 @@ def load_assets():
|
|
73 |
return tool
|
74 |
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
|
86 |
-
def
|
87 |
client = openai.OpenAI(
|
88 |
api_key='sk-or-vv-44ca318747a45e810149bf769e9dfbe5f42046695875efd7c9121cca590d6906',
|
89 |
base_url='https://api.vsegpt.ru/v1'
|
90 |
)
|
91 |
response = client.chat.completions.create(
|
92 |
model="gpt-4o-mini",
|
93 |
-
messages=[{"role": "user", "content":
|
94 |
).choices[0].message.content
|
95 |
|
96 |
return response
|
97 |
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
def check_text(text, tool):
|
100 |
matches = tool.check(text)
|
101 |
errors = []
|
102 |
for match in matches:
|
|
|
|
|
103 |
error_info = {
|
104 |
'start': match.offset,
|
105 |
'end': match.offset + match.errorLength,
|
106 |
-
'message': generate_gpt_comment(
|
107 |
}
|
108 |
errors.append(error_info)
|
109 |
|
|
|
73 |
return tool
|
74 |
|
75 |
|
76 |
+
def generate_gpt_comment_openai(inp):
|
77 |
+
response = openai.ChatCompletion.create(
|
78 |
+
model="gpt-4o-mini",
|
79 |
+
messages=[
|
80 |
+
{"role": "user", "content": inp}
|
81 |
+
]
|
82 |
+
)
|
83 |
+
return response.choices[0].message['content']
|
84 |
|
85 |
|
86 |
+
def generate_gpt_comment_vsegpt(inp):
|
87 |
client = openai.OpenAI(
|
88 |
api_key='sk-or-vv-44ca318747a45e810149bf769e9dfbe5f42046695875efd7c9121cca590d6906',
|
89 |
base_url='https://api.vsegpt.ru/v1'
|
90 |
)
|
91 |
response = client.chat.completions.create(
|
92 |
model="gpt-4o-mini",
|
93 |
+
messages=[{"role": "user", "content": inp}]
|
94 |
).choices[0].message.content
|
95 |
|
96 |
return response
|
97 |
|
98 |
|
99 |
+
def generate_gpt_comment(inp, client_name):
|
100 |
+
if client_name == "openai":
|
101 |
+
return generate_gpt_comment_openai(inp)
|
102 |
+
elif client_name == "vsegpt":
|
103 |
+
return generate_gpt_comment_vsegpt(inp)
|
104 |
+
else:
|
105 |
+
raise ValueError(f"Unsupported client: {client_name}")
|
106 |
+
|
107 |
+
|
108 |
def check_text(text, tool):
|
109 |
matches = tool.check(text)
|
110 |
errors = []
|
111 |
for match in matches:
|
112 |
+
inp = prompt.format(text[match.offset:match.offset + match.errorLength],
|
113 |
+
match.message, match.context)
|
114 |
error_info = {
|
115 |
'start': match.offset,
|
116 |
'end': match.offset + match.errorLength,
|
117 |
+
'message': generate_gpt_comment(inp, client_name="openai"),
|
118 |
}
|
119 |
errors.append(error_info)
|
120 |
|