Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/integration-OpenAI-autolog #495

Merged
merged 30 commits into from
Apr 28, 2024
Merged

Feat/integration-OpenAI-autolog #495

merged 30 commits into from
Apr 28, 2024

Conversation

KashiwaByte
Copy link
Contributor

@KashiwaByte KashiwaByte commented Apr 24, 2024

Description

openai的api key设置需要用环境变量,临时设置:

export OPENAI_API_KEY='你的API Key'

openai<=0.28

添加了与OpenAI 0.28及以前版本的autologging集成,需要安装openai==0.28
测试代码为:

import os
import sys
import openai
from swanlab.integration.openai import autolog

autolog(init=dict(experiment_name="openai_logging123"))

chat_request_kwargs = dict(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers"},
        {"role": "user", "content": "Where was it played?"},
    ],
)
response = openai.ChatCompletion.create(**chat_request_kwargs)

效果:
image.png

openai>=1.0

增加了OpenAI API的多版本集成支持,增加了Autologging对于Client类型方法改写的支持

from swanlab.integration.openai import autolog


autolog(init=dict(experiment_name="openai_autologging"))
client = autolog.client

# chat_completion

response = client.chat.completions.create(
    model="gpt-3.5-turbo-0125",
    messages=[
        {"role": "system", "content": "You are a helpful assistant designed to output JSON."},
        {"role": "user", "content": "Who won the world series in 2015?"},
    ],
)


response2 = client.chat.completions.create(
    model="gpt-3.5-turbo-0125",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Please write short story about ice cream?"},
    ],
)


# text_completion

response3 = client.completions.create(model="gpt-3.5-turbo-instruct", prompt="Write a song for jesus.")

image
image

Closes: #494, #500

@Zeyi-Lin Zeyi-Lin added this to the Integration milestone Apr 24, 2024
@Zeyi-Lin Zeyi-Lin added the 💪 enhancement New feature or request label Apr 24, 2024
@Zeyi-Lin Zeyi-Lin changed the title Feat/integration OpenAI autolog Feat/integration-OpenAI-autolog Apr 24, 2024
swanlab/__init__.py Outdated Show resolved Hide resolved
swanlab/data/__init__.py Outdated Show resolved Hide resolved
swanlab/integration/integration_utils/__init__.py Outdated Show resolved Hide resolved
swanlab/utils/get_modules.py Outdated Show resolved Hide resolved
swanlab/utils/timer.py Outdated Show resolved Hide resolved
@Zeyi-Lin
Copy link
Member

解决差不多了

@SAKURA-CAT SAKURA-CAT merged commit af9f23d into main Apr 28, 2024
@SAKURA-CAT SAKURA-CAT deleted the feat/integration-autolog branch April 28, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQUEST] 集成OpenAI AutoLog
3 participants