Skip to content

Commit

Permalink
Add kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed May 6, 2024
1 parent b06c5f5 commit 19de785
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion convertanything/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Type, get_args, get_origin, Union, List
import json
import openai
import uuid
from enum import Enum


Expand All @@ -11,7 +12,12 @@ def convertanything(
server="https://api.openai.com",
api_key=None,
llm="gpt-3.5-turbo-16k",
**kwargs,
):
if server.endswith("/"):
server = server[:-1]
if server.endswith("/v1"):
server = server[:-3]
input_string = str(input_string)
openai.base_url = f"{server}/v1/"
openai.api_key = api_key if api_key else server
Expand All @@ -38,13 +44,21 @@ def convertanything(
JSON Structured Output:
"""
response = ""
messages = [{"role": "system", "content": prompt}]
if "prompt_name" in kwargs:
messages[0]["prompt_name"] = kwargs["prompt_name"]
if "prompt_category" not in kwargs:
messages[0]["prompt_category"] = "Default"
else:
messages[0]["prompt_category"] = kwargs["prompt_category"]
completion = openai.chat.completions.create(
model=llm,
messages=[{"role": "user", "content": prompt}],
messages=messages,
temperature=0.5,
max_tokens=4096,
top_p=0.95,
stream=False,
user=str(uuid.uuid4()),
)
response = completion.choices[0].message.content
if "```json" in response:
Expand Down Expand Up @@ -78,13 +92,15 @@ def convert_list_of_dicts(
server="https://api.openai.com",
api_key=None,
llm="gpt-3.5-turbo-16k",
**kwargs,
):
converted_data = convertanything(
input_string=json.dumps(data[0]),
model=model,
server=server,
api_key=api_key,
llm=llm,
**kwargs,
)
mapped_list = remap_fields(converted_data=converted_data.model_dump(), data=data)
return mapped_list
2 changes: 1 addition & 1 deletion example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
" model=Person,\n",
" api_key=\"Your ezlocalai API Key\",\n",
" server=\"http://localhost:8091\",\n",
" llm=\"TinyLlama-1.1B-Chat-v1.0\",\n",
" llm=\"ezlocalai\",\n",
")\n",
"print(response)"
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="convertanything",
version="0.0.11",
version="0.0.12",
description="convertanything is a Python package that allows you to convert any text into a structured format according to the schema provided.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 19de785

Please sign in to comment.