Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed May 1, 2024
1 parent f09c0bd commit 015f3ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 2 additions & 11 deletions convertanything/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ def convertanything(
server="https://api.openai.com",
llm="gpt-3.5-turbo-16k",
):
if not isinstance(input_string, str):
input_string = str(input_string)
input_string = str(input_string)
openai.base_url = f"{server}/v1/"
openai.api_key = api_key if api_key else server
fields = model.model_fields
field_descriptions = [f"{field}: {fields[field]}" for field in fields]
schema = "\n".join(field_descriptions)
system_message = "Act as a JSON converter that converts any text into the desired JSON format based on the schema provided. Respond only with JSON in a properly formatted markdown code block, no explanations."
if not llm.startswith("gpt"):
system_message += " After the request is fulfilled, end with </s>."
prompt = f"""
prompt = f"""Act as a JSON converter that converts any text into the desired JSON format based on the schema provided. Respond only with JSON in a properly formatted markdown code block, no explanations.
**Reformat the following information into a structured format according to the schema provided:**
## Information:
Expand All @@ -33,18 +29,13 @@ def convertanything(
JSON Structured Output:
"""
response = ""
if llm.startswith("gpt"):
prompt = f"{system_message}\n{prompt}"
completion = openai.chat.completions.create(
model=llm,
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
max_tokens=1024,
top_p=0.95,
stream=False,
extra_body={
"system_message": system_message,
},
)
response = completion.choices[0].message.content
if "```json" in 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.6",
version="0.0.8",
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 015f3ab

Please sign in to comment.