Update gigiachat_requests.py
Browse files- gigiachat_requests.py +44 -1
gigiachat_requests.py
CHANGED
@@ -76,4 +76,47 @@ def get_completion_from_gigachat(prompt, max_tokens, access_token):
|
|
76 |
response_data = response.json()
|
77 |
answer_from_llm = response_data['choices'][0]['message']['content']
|
78 |
|
79 |
-
return answer_from_llm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
response_data = response.json()
|
77 |
answer_from_llm = response_data['choices'][0]['message']['content']
|
78 |
|
79 |
+
return answer_from_llm
|
80 |
+
|
81 |
+
def process_transcribation_with_gigachat(prompt, transcript, access_token):
|
82 |
+
url_completion = os.getenv('GIGA_COMPLETION_URL')
|
83 |
+
|
84 |
+
data_copm = json.dumps({
|
85 |
+
"model": 'GigaChat-Plus',
|
86 |
+
"messages": [
|
87 |
+
{
|
88 |
+
"role": "user",
|
89 |
+
"content": prompt + transcript
|
90 |
+
}
|
91 |
+
],
|
92 |
+
"stream": True,
|
93 |
+
})
|
94 |
+
|
95 |
+
headers_comp = {
|
96 |
+
'Content-Type': 'application/json',
|
97 |
+
'Accept': 'application/json',
|
98 |
+
'Authorization': 'Bearer ' + access_token
|
99 |
+
}
|
100 |
+
|
101 |
+
output_text = ''
|
102 |
+
st.write("Результат обработки:")
|
103 |
+
text_container = st.empty()
|
104 |
+
response = requests.post(url_completion, headers=headers_comp, data=data_copm, verify=False, stream=True)
|
105 |
+
for line in response.iter_lines():
|
106 |
+
if line:
|
107 |
+
decoded_line = line.decode('utf-8')
|
108 |
+
if decoded_line.startswith('data:'):
|
109 |
+
decoded_line = decoded_line[len('data:'):].strip()
|
110 |
+
try:
|
111 |
+
data = json.loads(decoded_line)
|
112 |
+
if "choices" in data:
|
113 |
+
for choice in data["choices"]:
|
114 |
+
if "delta" in choice and "content" in choice["delta"]:
|
115 |
+
output_text += choice["delta"]["content"]
|
116 |
+
text_container.text(output_text)
|
117 |
+
except json.JSONDecodeError:
|
118 |
+
continue
|
119 |
+
|
120 |
+
|
121 |
+
return output_text
|
122 |
+
|