ianarawjo / ianarawjo/ChainForge
Feature request: add support for OpenAI O1/o1-mini model
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 256
- Avg merge
- 4h 40m
- Merged PRs (30d)
- 22
Description
I'm currently trying to use OpenAI's o1 and o1-mini models through chainforge's custom provider, but encountering difficulties with the implementation. While o1-mini works occasionally, o1-preview-2024-09-12 consistently returns a 400 Bad Request error when making API calls.
## Current Setup
- Using custom provider implementation
- Successfully connected to OpenAI API
- o1-mini works in some cases
- o1-preview-2024-09-12 and o1-preview fails with 400 error
## Feature Request
Would it be possible to add native support for OpenAI's o1 model family in chainforge? This would:
- Ensure proper parameter handling for these models
- Provide better integration with chainforge's existing OpenAI support
- Help users avoid implementation issues with custom providers
## Impact
Native support would benefit users who want to:
- Experiment with OpenAI's latest models
- Compare results between different model versions
- Build reliable workflows using these models
Let me know if you need any additional information. Looking forward to your response!
I let AI to help me built a custom provider file, but only worked for o1-mini, not sure why o1-preview is not working:
```
# -*- coding: utf-8 -*-
from chainforge.providers import provider
import requests
import urllib3
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
# Disable SSL warnings
urllib3.disable_warnings()
THIRD_PARTY_GPT_SETTINGS_SCHEMA = {
"settings": {
"temperature": {
"type": "number",
"title": "temperature",
"description": "Controls the 'creativity' or randomness of the response.",
"default": 1,
"minimum": 0,
"maximum": 1.0,
"multipleOf": 0.1,
},
"max_completion_tokens": {
"type": "integer",
"title": "max_completion_tokens",
"description": "Maximum number of tokens to generate in the response.",
"default": 65536,
"minimum": 1,
"maximum": 65536,
},
"presence_penalty": {
"type": "number",
"title": "Presence Penalty",
"description": "Penalize new tokens based on their presence in the text so far.",
"default": 0,
"minimum": -2.0,
"maximum": 2.0,
"multipleOf": 0.1,
},
"frequency_penalty": {
"type": "number",
"title": "Frequency Penalty",
"description": "Penalize new tokens based on their frequency in the text so far.",
"default": 0,
"minimum": -2.0,
"maximum": 2.0,
"multipleOf": 0.1,
},
},
"ui": {
"temperature": {
"ui:help": "Defaults to 1.",
"ui:widget": "range"
},
"max_completion_tokens": {
"ui:help": "Defaults to 100.",
"ui:widget": "range"
},
}
}
@provider(name="o1-model",
emoji="\U0001F680",
models=["o1-mini", "o1-preview-2024-09-12"],
rate_limit="sequential",
settings_schema=THIRD_PARTY_GPT_SETTINGS_SCHEMA)
def third_party_gpt_v2_completion(prompt: str, model: str, temperature: float = 1, max_completion_tokens: int = 1000, **kwargs) -> str:
url = "https://api.openai.com/v1/chat/completions"
# Create a session and configure the retry mechanism
session = requests.Session()
retry = Retry(
total=5, # Increase the number of retries
backoff_factor=0.5,
status_forcelist=[408, 429, 500, 502, 503, 504]
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('https://', adapter)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY" # Replace YOUR_API_KEY with your actual API key
}
data = {
"model": model,
"messages": [{"role": "user", "content": prompt}],
"temperature": temperature,
"max_completion_tokens": max_completion_tokens
}
# Disable SSL verification
response = session.post(url, headers=headers, json=data, verify=False, timeout=360)
response.raise_for_status()
result = response.json()
return result["choices"][0]["message"]["content"]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting ChainForge’s existing OpenAI support and the custom provider entry point shown in the issue, then compare how o1-preview and o1-mini requests are handled. Confirm the required model parameters and API behavior, and verify that native support works for both listed o1 models without the reported 400 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- ai, api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100