Merge pull request #581 from pchalasani/langroid-example

shorter langroid example, update section title
This commit is contained in:
Ishaan Jaff 2023-10-11 07:57:28 -07:00 • committed by GitHub
commit 24ea5e00b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -137,7 +137,7 @@ $ litellm --model command-nightly
[**Jump to Code**](https://github.com/BerriAI/litellm/blob/fef4146396d5d87006259e00095a62e3900d6bb4/litellm/proxy.py#L36)
## [Tutorial]: Use with Aider/AutoGen/Continue-Dev
## [Tutorial]: Use with Aider/AutoGen/Continue-Dev/Langroid
Here's how to use the proxy to test codellama/mistral/etc. models for different github repos
@ -217,26 +217,19 @@ pip install langroid
```python
from langroid.language_models.openai_gpt import OpenAIGPTConfig, OpenAIGPT
# create the (Pydantic-derived) config class: Allows setting params via MYLLM_XXX env vars
MyLLMConfig = OpenAIGPTConfig.create(prefix="myllm")
# instantiate the class, with the model name and context length
my_llm_config = MyLLMConfig(
chat_model="local/localhost:8000", # "local/[URL where LiteLLM proxy is listening]
# configure the LLM
my_llm_config = OpenAIGPTConfig(
#format: "local/[URL where LiteLLM proxy is listening]
chat_model="local/localhost:8000",
chat_context_length=2048, # adjust based on model
)
# create llm and interact with it
from langroid.language_models.base import LLMMessage, Role
# create llm, one-off interaction
llm = OpenAIGPT(my_llm_config)
messages = [
LLMMessage(content="You are a helpful assistant", role=Role.SYSTEM),
LLMMessage(content="What is the capital of Ontario?", role=Role.USER),
],
response = mdl.chat(messages, max_tokens=50)
response = mdl.chat("What is the capital of China?", max_tokens=50)
# Create an Agent with this LLM, wrap it in a Task, and run it as an interactive chat app:
# Create an Agent with this LLM, wrap it in a Task, and
# run it as an interactive chat app:
from langroid.agent.base import ChatAgent, ChatAgentConfig
from langroid.agent.task import Task