Для разработчиков
Python example:
Пример приведен для старой версии библиотеки openai
import openai # openai==0.28
openai.api_key = "sk_xxx" # Ваш API ключ
openai.api_base = "https://eu.neuroapi.host/v1" # Наш API Endpoint
def main():
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "write a poem about a tree"}],
stream=True,
)
if isinstance(chat_completion, dict):
# not stream
print(chat_completion.choices[0].message.content)
else:
# stream
for token in chat_completion:
content = token["choices"][0]["delta"].get("content")
if content != None:
print(content, end="", flush=True)
if __name__ == "__main__":
main()
Пример для новой библиотеки:
import openai # версия openai не менее 1.0
# optional; defaults to `os.environ['OPENAI_API_KEY']`
openai.api_key = 'sk_xxx' # Ваш API ключ
# all client options can be configured just like the `OpenAI` instantiation counterpart
openai.base_url = "https://eu.neuroapi.host/v1" # Наш API Endpoint
openai.default_headers = {"x-foo": "true"}
completion = openai.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "How do I output all files in a directory using Python?",
},
],
)
print(completion.choices[0].message.content)
Last updated