Skip to content

Commit 19de785

Browse files
committed
Add kwargs
1 parent b06c5f5 commit 19de785

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

convertanything/__init__.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Type, get_args, get_origin, Union, List
33
import json
44
import openai
5+
import uuid
56
from enum import Enum
67

78

@@ -11,7 +12,12 @@ def convertanything(
1112
server="https://api.openai.com",
1213
api_key=None,
1314
llm="gpt-3.5-turbo-16k",
15+
**kwargs,
1416
):
17+
if server.endswith("/"):
18+
server = server[:-1]
19+
if server.endswith("/v1"):
20+
server = server[:-3]
1521
input_string = str(input_string)
1622
openai.base_url = f"{server}/v1/"
1723
openai.api_key = api_key if api_key else server
@@ -38,13 +44,21 @@ def convertanything(
3844
JSON Structured Output:
3945
"""
4046
response = ""
47+
messages = [{"role": "system", "content": prompt}]
48+
if "prompt_name" in kwargs:
49+
messages[0]["prompt_name"] = kwargs["prompt_name"]
50+
if "prompt_category" not in kwargs:
51+
messages[0]["prompt_category"] = "Default"
52+
else:
53+
messages[0]["prompt_category"] = kwargs["prompt_category"]
4154
completion = openai.chat.completions.create(
4255
model=llm,
43-
messages=[{"role": "user", "content": prompt}],
56+
messages=messages,
4457
temperature=0.5,
4558
max_tokens=4096,
4659
top_p=0.95,
4760
stream=False,
61+
user=str(uuid.uuid4()),
4862
)
4963
response = completion.choices[0].message.content
5064
if "```json" in response:
@@ -78,13 +92,15 @@ def convert_list_of_dicts(
7892
server="https://api.openai.com",
7993
api_key=None,
8094
llm="gpt-3.5-turbo-16k",
95+
**kwargs,
8196
):
8297
converted_data = convertanything(
8398
input_string=json.dumps(data[0]),
8499
model=model,
85100
server=server,
86101
api_key=api_key,
87102
llm=llm,
103+
**kwargs,
88104
)
89105
mapped_list = remap_fields(converted_data=converted_data.model_dump(), data=data)
90106
return mapped_list

example.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
" model=Person,\n",
4747
" api_key=\"Your ezlocalai API Key\",\n",
4848
" server=\"http://localhost:8091\",\n",
49-
" llm=\"TinyLlama-1.1B-Chat-v1.0\",\n",
49+
" llm=\"ezlocalai\",\n",
5050
")\n",
5151
"print(response)"
5252
]

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="convertanything",
13-
version="0.0.11",
13+
version="0.0.12",
1414
description="convertanything is a Python package that allows you to convert any text into a structured format according to the schema provided.",
1515
long_description=long_description,
1616
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)