Skip to main content

A Python wrapper for managing OpenAI API and other LLM models.

Project description

LLM Tools

This package wraps the OpenAI API and other LLM models that share the completion endpoint feature. It provides a simple interface to generate text from a prompt.

Installation

pip install llm-tools

Usage

from llm_tools.openai import prompt
from pathlib import Path


# Create a prompt object that will be logged to the `my-task` directory under the
# current working directory.
# The PromptZeros class will use arguments that will maximize the determinism of the outputs.
pz = prompt.PromptZeros(Path("./"), "my-task")

# Send a prompt to the API and return the response.
w = pz.send_prompt("What is the WDI code for GDP?", return_data=True)

# Print the response.
print(w)

# Output:

# {'message': [{'role': 'system', 'content': ''}, {'role': 'user', 'content': 'What is the WDI code for GDP?'}], 'response': {'id': 'chatcmpl-8V0IN0VbeYTrsBAohs309DHJQLJL8', 'choices': [{'finish_reason': 'stop', 'index': 0, 'message': {'content': 'The WDI code for GDP (Gross Domestic Product) is "NY.GDP.MKTP.CD".', 'role': 'assistant', 'function_call': None, 'tool_calls': None}}], 'created': 1702399995, 'model': 'gpt-3.5-turbo-0613', 'object': 'chat.completion', 'system_fingerprint': None, 'usage': {'completion_tokens': 23, 'prompt_tokens': 20, 'total_tokens': 43}}, 'content': 'The WDI code for GDP (Gross Domestic Product) is "NY.GDP.MKTP.CD".', 'api_kwargs': {'temperature': 0, 'top_p': 0, 'n': 1, 'stream': False, 'frequency_penalty': 0, 'presence_penalty': 0, 'model': 'gpt-3.5-turbo', 'max_tokens': 4029}, 'metadata': {}, 'message_hash': '1a5816095c232f29428d4cec70498391'}

NOTE: The output is also logged to the my-task directory under the current working directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_commons-0.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

llm_commons-0.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_commons-0.0.1.tar.gz.

File metadata

  • Download URL: llm_commons-0.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Darwin/23.1.0

File hashes

Hashes for llm_commons-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3c1b0335e8e39d430d9a226d9e1bc6b4183fc3246590f2b29830dc8c9f784cd2
MD5 21480c07492b7ddd67692ffdee39347d
BLAKE2b-256 75f0920a367508400b2bc279ef3d630d23a3bf287e5534bf8662ee3f58d24f29

See more details on using hashes here.

File details

Details for the file llm_commons-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: llm_commons-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Darwin/23.1.0

File hashes

Hashes for llm_commons-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ebe9bc2560b76ab3a7f1652824629fb21e6811f4ffc3ae8ce62b003834686ed
MD5 15a9d695d7819a95fe2046b98e750c74
BLAKE2b-256 e469a4caefa7e3c8079eb17cd29b1fc8289a7bcf5197508443901daaf6a97b58

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page