Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Created January 30, 2024 13:08
Show Gist options
  • Save john-adeojo/2a88c97602fdd2b2ab74250de4c90708 to your computer and use it in GitHub Desktop.
Save john-adeojo/2a88c97602fdd2b2ab74250de4c90708 to your computer and use it in GitHub Desktop.
from autogen import OpenAIWrapper
import json
config_list = [
{
"model": model_path,
"api_key": 'sk-111111111111111111111111111111111111111111111111',
"base_url": vllm_endpoint, # Replace with your Runpod endpoint. Ensure that you tack "/v1" on the end of your URL.
},
]
# Now pass this list when you create an instance of OpenAIWrapper
client = OpenAIWrapper(config_list=config_list)
def valid_json_filter(response, **_):
for text in OpenAIWrapper.extract_text_or_completion_object(response):
try:
json.loads(text)
return True
except ValueError:
pass
return False
prompt = "What is AI?"
response = client.create(
prompt=prompt,
filter_func=valid_json_filter,
max_tokens=250
)
response.choices[0].text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment