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

Hope to support third-party OpenAI sites #34

Open
jinshuqishi2019 opened this issue Aug 20, 2024 · 1 comment
Open

Hope to support third-party OpenAI sites #34

jinshuqishi2019 opened this issue Aug 20, 2024 · 1 comment

Comments

@jinshuqishi2019
Copy link

Is your feature request related to a problem? Please describe.
I use this link openai_api_url: https://myhost.com/v1/chat/completions because it's cheaper, but it doesn't work and still accesses api.openai.com. I hope that third-party OpenAI sites can be supported in the future.

@jinshuqishi2019
Copy link
Author

def call_openai_api(api_url, combined_content, model, api_key):
    """Call the OpenAI API with the given parameters."""
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {api_key}'
    }
    data = {
        "model": model,
        "messages": [
            {"role": "system", "content": "You are a professional assistant, skilled in composing detailed and accurate news articles from multiple sources."},
            {"role": "user", "content": combined_content}
        ]
    }
    try:
        response = requests_retry_session().post(api_url, headers=headers, json=data)
        response.raise_for_status()
        response_json = response.json()
        return response_json['choices'][0]['message']['content']
    except requests.RequestException as e:
        logger.error("OpenAI API request failed: %s", e)
        return None
    except (KeyError, ValueError) as e:
        logger.error("Failed to parse JSON response from OpenAI API: %s", e)
        return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant