gateway icon indicating copy to clipboard operation
gateway copied to clipboard

Running the Gateway locally

Open nlpravi opened this issue 1 year ago • 0 comments

Hi I'm having an issue running the gateway locally. Here is my code. I get the error "TypeError: Completions.create() got an unexpected keyword argument 'headers'". Can you please help?

from openai import OpenAI from langchain_openai import ChatOpenAI portkey_config = { "retry": { "attempts": 3 }, "cache": { "mode": "semantic", "max_age":10000, }, "strategy": { "mode": "loadbalance" }, "targets": [ { "provider": "azure-openai", "resource_name":"xxxxx", "deployment_id":"xxxxxx", "api_version": "2023-03-15-preview", "api_key":"xxxxx", "weight": 0.5 }, { "provider": "together", "api_key":"xxxxx", "weight": 0.5 } ] }

client = ChatOpenAI(base_url='https://127.0.0.1:8787', api_key='hello_world', headers = { 'x-portkey-config': portkey_config, })

print(client) from langchain.prompts.chat import ChatPromptTemplate from langchain.schema import BaseOutputParser

class CommaSeparatedListOutputParser(BaseOutputParser): """Parse the output of an LLM call to a comma-separated list."""

def parse(self, text: str):
    """Parse the output of an LLM call."""
    return text.strip().split(", ")

template = """You are a helpful assistant who generates comma separated lists. A user will pass in a category, and you should generate 5 objects in that category in a comma separated list. ONLY return a comma separated list, and nothing more."""

human_template = "{text}"

chat_prompt = ChatPromptTemplate.from_messages([ ("system", template), ("human", human_template), ]) chain = chat_prompt | client | CommaSeparatedListOutputParser() print(chain.invoke({"text": "Colors"}))

nlpravi avatar Jan 22 '24 22:01 nlpravi