Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed May 7, 2024
1 parent 2842168 commit 5b012ed
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 2 deletions.
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,65 @@
pip install convertanything
```

## Usage
## Usage Examples

### ezLocalai

To use with [ezLocalai](https://github.com/DevXT-LLC/ezlocalai) in Python, make sure your ezLocalai server is running then run the following code:

```python
from convertanything import convertanything
from pydantic import BaseModel
from typing import List


class Person(BaseModel):
name: str
age: int
email: str
interests: List[str]


response = convertanything(
input_string="Hi my name is John Doe, I am 30 years old, my email is [email protected] . I like to go fishing and watching football.",
model=Person,
api_key="Your ezlocalai API Key",
server="http://localhost:8091",
)
print(response)
```

### AGiXT

To use with [AGiXT](https://github.com/Josh-XT/AGiXT) in Python, make sure your AGiXT server is running then run the following code:

```python
from convertanything import convertanything
from pydantic import BaseModel
from typing import List


class Person(BaseModel):
name: str
age: int
email: str
interests: List[str]


response = convertanything(
input_string="Hi my name is John Doe, I am 30 years old, my email is [email protected] . I like to go fishing and watching football.",
model=Person,
api_key="Your AGiXT API Key",
server="http://localhost:7437",
llm="Your AGiXT Agent Name",
prompt_name="User Input",
)
print(response)
```

### OpenAI

If you have an OpenAI API key, you can use it as follows with OpenAI language models:

```python
from convertanything import convertanything
Expand All @@ -25,6 +83,7 @@ response = convertanything(
input_string="Hi my name is John Doe, I am 30 years old, my email is [email protected] . I like to go fishing.",
model=Person,
api_key="Your OpenAI API Key",
llm="gpt-3.5-turbo",
)
print(response)
```
84 changes: 83 additions & 1 deletion example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
"Alternatively, to use with OpenAI API, you can remove the `server` and `llm` parameters and enter your OpenAI API key in the `api_key` parameter to use OpenAI API with the `gpt-3.5-turbo-16k` model or define which LLM you want to use with the `llm` parameter.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ezLocalai\n",
"\n",
"To use with [ezLocalai](https://github.com/DevXT-LLC/ezlocalai) in Python, make sure your ezLocalai server is running then run the following code:\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
Expand Down Expand Up @@ -46,7 +55,80 @@
" model=Person,\n",
" api_key=\"Your ezlocalai API Key\",\n",
" server=\"http://localhost:8091\",\n",
" llm=\"ezlocalai\",\n",
")\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### AGiXT\n",
"\n",
"To use with [AGiXT](https://github.com/Josh-XT/AGiXT) in Python, make sure your AGiXT server is running then run the following code:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from convertanything import convertanything\n",
"from pydantic import BaseModel\n",
"from typing import List\n",
"\n",
"\n",
"class Person(BaseModel):\n",
" name: str\n",
" age: int\n",
" email: str\n",
" interests: List[str]\n",
"\n",
"\n",
"response = convertanything(\n",
" input_string=\"Hi my name is John Doe, I am 30 years old, my email is [email protected] . I like to go fishing and watching football.\",\n",
" model=Person,\n",
" api_key=\"Your AGiXT API Key\",\n",
" server=\"http://localhost:7437\",\n",
" llm=\"Your AGiXT Agent Name\",\n",
" prompt_name=\"User Input\",\n",
")\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### OpenAI\n",
"\n",
"If you have an OpenAI API key, you can use it as follows with OpenAI language models:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from convertanything import convertanything\n",
"from pydantic import BaseModel\n",
"from typing import List\n",
"\n",
"\n",
"class Person(BaseModel):\n",
" name: str\n",
" age: int\n",
" email: str\n",
" interests: List[str]\n",
"\n",
"\n",
"response = convertanything(\n",
" input_string=\"Hi my name is John Doe, I am 30 years old, my email is [email protected] . I like to go fishing.\",\n",
" model=Person,\n",
" api_key=\"Your OpenAI API Key\",\n",
" llm=\"gpt-3.5-turbo\",\n",
")\n",
"print(response)"
]
Expand Down

0 comments on commit 5b012ed

Please sign in to comment.