Spaces:
Running
Running
import openai | |
import streamlit as st | |
def generate_rewrite(model_name, instruction, user_text): | |
messages = [ | |
{"role": "system", "content": instruction}, | |
{"role": "user", "content": user_text} | |
] | |
try: | |
response = openai.ChatCompletion.create( | |
model=model_name, | |
messages=messages, | |
max_tokens=500, | |
temperature=0.9, | |
top_p=0.9, | |
n=1, | |
) | |
assistant_response = response['choices'][0]['message']['content'].strip() | |
return assistant_response | |
except Exception as e: | |
st.error(f"Ошибка при генерации рерайта с помощью {model_name}: {e}") | |
return None |