codex icon indicating copy to clipboard operation
codex copied to clipboard

Support for local / other LLMs

Open imggion opened this issue 1 year ago • 52 comments

Image

I’d love to be able to use Codex locally, for example to ask it questions about my system, my server, and everything I have on my computer, without necessarily having to go through your servers.

That would be really cool and would give everyone the opportunity to have full control over their own data.

imggion avatar Apr 16 '25 17:04 imggion

The current logic supports the openai sdk, but we are excited to review contributions that would decouple this if done without introducing significant complexity to the project.

Some parts about the code patch format that the model is expected to generate are quite specific to the openai models as we have seen this improve general accuracy and model performance, and so at the moment this isn't a trivial refactor and change.

tibo-openai avatar Apr 16 '25 18:04 tibo-openai

@tibo-openai I’d be very happy to find a way to introduce this without making the project too complex.

imggion avatar Apr 16 '25 18:04 imggion

Will there be support for Azure OpenAI? I don’t see an option to set a custom endpoint. This would be a great addition for enterprise use

nannan-motorq avatar Apr 16 '25 18:04 nannan-motorq

i knew this would be the very first question people will be asking 😁

Pl8tinium avatar Apr 16 '25 19:04 Pl8tinium

There doesn't seem to be any as far as I can see

https://github.com/openai/codex/issues/14#issuecomment-2810871348

KorigamiK avatar Apr 16 '25 21:04 KorigamiK

This project is currently using the /responses endpoint from OpenAI's API. Ollama has compatibility with some OpenAI API endpoints, but the /responses endpoint is not included yet. If Ollama supported this endpoint, we could simply update the OPENAI_BASE_URL variable (defined here) to point directly to the Ollama URL.

I've opened an issue in the Ollama repository about this

vmotta8 avatar Apr 17 '25 00:04 vmotta8

Hi all,

Would the maintainers be open to adding a lightweight LLMProvider abstraction in the CLI? The idea is to decouple transport from prompt/patch logic, so you could plug in OpenAI, Ollama (or any other backend).

E.g., an interface:

interface LLMProvider { complete(prompt: string, opts: any): Promise; }

and two simple adapters (OpenAIProvider for /responses, OllamaProvider for /completions + wrap). Defaults remain on OpenAI.

This keeps the CLI flexible for local/offline models while preserving existing behavior. Curious if this aligns with the repo’s roadmap - thanks!

rjxby avatar Apr 17 '25 01:04 rjxby

I just found this fork which uses the completions api to work with gemini! It could probably work with ollama as well https://github.com/ymichael/codex

SawyerHood avatar Apr 17 '25 02:04 SawyerHood

The best current way to do this is to use LiteLLM Proxy. You can quickly spin one up locally.

https://docs.litellm.ai/docs/simple_proxy

All you have to do is set OPENAI_BASE_URL to your local LiteLLM proxy and then you can set OPENAI_API_KEY to your LiteLLM proxy key.

Voila, you can configure any model you want from any provider that supports Responses API (currently only directly to OpenAI, but should be available for other providers soon) and codex works!

marty-sullivan avatar Apr 17 '25 03:04 marty-sullivan

Is that possible to set BASE_URL in https://github.com/openai/codex/blob/main/codex-cli/src/utils/agent/agent-loop.ts#L255

DuinoDu avatar Apr 17 '25 04:04 DuinoDu

The best current way to do this is to use LiteLLM Proxy. You can quickly spin one up locally.

https://docs.litellm.ai/docs/simple_proxy

All you have to do is set OPENAI_BASE_URL to your local LiteLLM proxy and then you can set OPENAI_API_KEY to your LiteLLM proxy key.

Voila, you can configure any model you want from any provider that supports Responses API (currently only directly to OpenAI, but should be available for other providers soon) and codex works!

I do not believe that litellm would build responses api upon chat completions (which is supported by most third party provider) because of lack of ability.

tcztzy avatar Apr 17 '25 04:04 tcztzy

@tcztzy They have implemented Responses API already, it is just not supported for all providers yet. They are adding Azure support this week:

https://github.com/BerriAI/litellm/issues/9653#issuecomment-2811760812

Appreciate the downvote though.

marty-sullivan avatar Apr 17 '25 05:04 marty-sullivan

https://github.com/mudler/LocalAI lets you host local LLMs with /v1/responses Can't wait to try it out!

mrmartin avatar Apr 17 '25 06:04 mrmartin

@marty-sullivan I know, but azure's responses api is not implemented by litellm, litellm would not and could not do such a tough task. I prefer write by myself.

tcztzy avatar Apr 17 '25 08:04 tcztzy

What about https://github.com/open-responses/open-responses?

lolrazh avatar Apr 17 '25 12:04 lolrazh

After reviewing more of the request pipeline (especially around the /responses endpoint and tool support), I realize this implementation heavily relies on OpenAI-specific features.

Particularly: The tools field enables structured function calls (like shell) which Ollama doesn’t support yet. The /responses endpoint returns streaming patches and reasoning metadata, which aren’t part of most third-party APIs (including Ollama’s /generate or /completions). Features like reasoning hints and Codex-style diff handling also seem tightly coupled to OpenAI models.

https://github.com/openai/codex/blob/b0ccca555685b1534a0028cb7bfdcad8fe2e477a/codex-cli/src/utils/agent/agent-loop.ts#L512

So at this point, it looks like supporting third-party models would require a separate, more limited execution path - or a pluggable provider setup that degrades gracefully when features like tools aren’t available. Please correct me if I'm wrong.

Appreciate everyone’s thoughts - mostly leaving this here in case others are exploring similar directions!

rjxby avatar Apr 17 '25 13:04 rjxby

What about https://github.com/open-responses/open-responses?

Great, even currently not support DeepSeek official api, but we can access through openrouter.

tcztzy avatar Apr 17 '25 13:04 tcztzy

I just set up open-responses and it works. Tool Use is currently disabled because it is only partially implemented in the library, but seems like it is on the roadmap. https://github.com/lolrazh/codex

https://github.com/user-attachments/assets/b1bdc00d-f971-4fc2-84eb-a9cb8269b81c

lolrazh avatar Apr 17 '25 14:04 lolrazh

@marty-sullivan I know, but azure's responses api is not implemented by litellm, litellm would not and could not do such a tough task. I prefer write by myself.

@tcztzy I have no idea what you mean by this... Did you not go to the issue that I linked? They are literally implementing it for Azure right now. They already have it implemented for OpenAI. Their entire business is creating parity with the OpenAI API

marty-sullivan avatar Apr 17 '25 14:04 marty-sullivan

Re-purposing this thread for general support of other LLMs and model providers. There are a series of refactors needed to support this and I would be excited to help here in reviewing a solid plan that allows us to keep excellent support for the current set of models, without ending up in a worst of all worlds scenario and where certain features can be better supported or toggled based on whether the underlying models / api support it well.

tibo-openai avatar Apr 17 '25 14:04 tibo-openai