Doriandarko / o1-engineer

o1-engineer is a command-line tool designed to assist developers in managing and interacting with their projects efficiently. Leveraging the power of OpenAI's API, this tool provides functionalities such as code generation, file editing, and project planning to streamline your development workflow.
2.8k stars 294 forks source link

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

Open tronics opened 1 month ago

tronics commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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