From eff2c96732325f0582086e2035dab79122e671c6 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 31 Jan 2025 14:35:42 +0100 Subject: [PATCH] Include x-coding-assistant=open-interpreter header in litellm calls Proxies that inspect traffic between the development environment and an LLM might be interested in whether it's OI or another tool calling in order to be able to inspect and/or modify the payload. The most common way of solving this would be to add a `user-agent` header. However, litellm which OI uses calls into OpenAI libraries directly when making the request and it seems like the only way to set a custom `http_client`. This seemed like something that might have unforeseen consequences (timeouts? retries?). For other LLMs, litellm seems to use its own httpx wrapper which might presumably be easier to customize, but I have not tried. To make things easier, let's just add an OI specific header. I put the string OI followed by the version there, but the value - and indeed the key - of the header are not that interesting, what I would like to do is to just be able to to tell OI calls. --- interpreter/core/llm/__init__.py | 14 ++++++++++++++ interpreter/core/llm/llm.py | 2 ++ 2 files changed, 16 insertions(+) diff --git a/interpreter/core/llm/__init__.py b/interpreter/core/llm/__init__.py index e69de29bb2..d8472cd980 100644 --- a/interpreter/core/llm/__init__.py +++ b/interpreter/core/llm/__init__.py @@ -0,0 +1,14 @@ +from importlib import metadata + +_VERSION = "dev" + + +def __get_version(): + try: + version = metadata.version("open-interpreter") + except metadata.PackageNotFoundError: + version = _VERSION + return version + + +__version__ = __get_version() \ No newline at end of file diff --git a/interpreter/core/llm/llm.py b/interpreter/core/llm/llm.py index 980672db58..d3bbf66bea 100644 --- a/interpreter/core/llm/llm.py +++ b/interpreter/core/llm/llm.py @@ -4,6 +4,7 @@ import sys import litellm +from . import __version__ litellm.suppress_debug_info = True litellm.REPEATED_STREAMING_CHUNK_LIMIT = 99999999 @@ -437,6 +438,7 @@ def fixed_litellm_completions(**params): first_error = None params["num_retries"] = 0 + params["headers"] = {"x-coding-assistant": f"open-interpreter/{__version__}"} for attempt in range(attempts): try: