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

Options when you do not have model access to o1 yet #17

Open
tronics opened this issue Oct 3, 2024 · 4 comments
Open

Options when you do not have model access to o1 yet #17

tronics opened this issue Oct 3, 2024 · 4 comments

Comments

@tronics
Copy link

tronics commented Oct 3, 2024

Hello,

I understand if you top up your openai API account with a cumulative sum of 1000 USD you have access to o1 and o1-preview immediately. So many developers interested in this fine script will hit a roadblock here.

I would suggest to add a few lines to explain how to get o1 access via a provider like openrouter, or other ones that are good and work.

Thank you.

Cheers

@ravinm123
Copy link

OpenRouter is a platform that allows you to access OpenAI's models, including o1 and o1-preview, without having to pay the cumulative sum of $1000.

@ovachiever
Copy link

See this PR, the o1-eng_OR.py file is setup to access the OpenRouter API endpoint for instant access to o1 models. All you'll need to do is add your OpenRouter API key.

@tronics
Copy link
Author

tronics commented Oct 4, 2024

Thank you.. your PR basically changes these lines:

MODEL = "openai/o1-mini"

Initialize the OpenAI client for OpenRouter endpoint

client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR KEY",
)

@ovachiever
Copy link

Also at the >>'s below:

    if is_edit_request:

changed prompt to prompt_message and message to message_content on the following two lines
prompt_message = EDIT_INSTRUCTION_PROMPT if retry_count == 0 else APPLY_EDITS_PROMPT
message_content = f"{prompt_message}\n\nUser request: {user_message}"
else:
message_content = user_message

    messages = [
        {"role": "user", "content": message_content}
    ]
    
    if is_edit_request and retry_count == 0:
        print(colored("Analyzing files and generating modifications...", "magenta"))
        logging.info("Sending edit request to AI.")
    elif not is_edit_request:
        print(colored("o1 engineer is thinking...", "magenta"))
        logging.info("Sending general query to AI.")

    response = client.chat.completions.create(
        model=MODEL,
        messages=messages,
        max_completion_tokens=60000
    )
    logging.info("Received response from AI.")
    last_ai_response = response.choices[0].message.content

    if not is_edit_request:
        # Update conversation history
        conversation_history.append(user_message)
        conversation_history.append(last_ai_response)
        if len(conversation_history) > 20:  # 10 interactions (user + AI each)
            conversation_history = conversation_history[-20:]

    return last_ai_response
except Exception as e:

Changed OpenAI to say OpenRouter on the following two lines
print(colored(f"Error while communicating with OpenRouter: {e}", "red"))
logging.error(f"Error while communicating with OpenRouter: {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

3 participants