Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostis Gourgoulias committed Jun 21, 2024
1 parent 2d579ee commit a7d37ce
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions textgrad/engine/local_model_openai_api.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import os
import logging
from openai import OpenAI
from .openai import ChatOpenAI

logger = logging.getLogger(__name__)


class ChatExternalClient(ChatOpenAI):
"""
This is the same as engine.openai.ChatOpenAI, but we pass the
client explicitly to the constructor.
This is the same as engine.openai.ChatOpenAI, but we pass in an external OpenAI client.
"""

DEFAULT_SYSTEM_PROMPT = "You are a helpful, creative, and smart assistant."
client = None

def __init__(
self,
client,
model_string,
system_prompt=DEFAULT_SYSTEM_PROMPT,
client: OpenAI,
model_string: str,
system_prompt: str = DEFAULT_SYSTEM_PROMPT,
**kwargs,
):
"""
:param client:
:param model_string:
:param system_prompt:
:param client: an OpenAI client object.
:param model_string: the model name, used for the cache file name and chat completion requests.
:param system_prompt: the system prompt to use in chat completions.
Example usage with lm-studio local server, but any client that follows the OpenAI API will work.
```python
from openai import OpenAI
from textgrad.engine.local_model_openai_api import ChatExternalClient
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
engine = ChatExternalClient(client=client, model_string="your-model-name")
print(engine.generate(max_tokens=40, prompt="What is the meaning of life?"))
```
"""

if os.getenv("OPENAI_API_KEY") is None:
Expand Down

0 comments on commit a7d37ce

Please sign in to comment.