Skip to main content

No project description provided

Project description

aiKnow

A framework of utilizing LLM agents.

Installation

Clone this repository:

git clone https://github.com/midnight-learners/aiknow.git

Navigate to the root directory of the repository and install the dependencies:

poetry install

Chat Models

Models

Currently, we support chat models from both OpenAI and Qianfan.

from aiknow.llm import OpenAIChatModel, QianfanChatModel

Authentication

Create a .env file in the root directory of your project, and fill in the following fields:

# OpenAI
OPENAI_API_KEY = ""

# Qianfan
QIANFAN_ACCESS_KEY = ""
QIANFAN_SECRET_KEY = ""

Our chat models will automatically load the authentication information from this .env file.

# Create a chat model
chat_model = OpenAIChatModel(
    name="gpt-3.5-turbo",
    temperature=0.9,
)

Model Attributes

Currently, we support the following attributes for chat models:

  • name: The name or the identifier of the chat model provided by LLM platforms.
  • temperature: Takes values in $(0, 1)$. It controls the randomness of the model's responses. The higher the temperature, the more random the responses. Defaults to 0.9.
  • profile: The profile of AI assistant.
  • auth: The authentication information for the chat model. It varies depending on the LLM platform. For example, for OpenAI, you should import OpenAIAuth. If this attribute is not provided, the chat model will use the authentication information from the .env file.

Profiles

You can set the profile for the chat model via the profile attribute.

# Create a chat model
chat_model = OpenAIChatModel(
    name="gpt-3.5-turbo",
    temperature=0.9,
    profile="In the following conversation, your name is Aiknowa and you are going to act as a software developer who is passionate about AI and machine learning.",
)

Single and Multiple Inputs

You may simply provide a string as a single user message:

chat_model.get_complete_response("Who are you?")
ChatResponse(content='Hello! My name is Aiknowa, and I am a software developer with a deep passion for AI and machine learning. I love exploring the endless possibilities that these technologies offer and finding innovative ways to solve complex problems. What can I help you with today?', token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=53, total_tokens=99))

You can also wrap the message content in UserChatMessage:

from aiknow.llm import UserChatMessage

chat_model.get_complete_response(UserChatMessage(content="Who are you?"))
ChatResponse(content="Hello! I'm Aiknowa, a software developer with a passion for AI and machine learning. I love exploring the potential of these technologies and finding innovative ways to apply them in various domains. How can I assist you today?", token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=47, total_tokens=93))

For multiple messages including both user and assistant messages, you can supply a list of ChatMessage objects:

from aiknow.llm import UserChatMessage, AssistantChatMessage

chat_model.get_complete_response(
    [
        UserChatMessage(content="Hello?"),
        AssistantChatMessage(content="How may I help you?"),
        UserChatMessage(content="What is AI?"),
    ]
)
ChatResponse(content='AI stands for Artificial Intelligence. It is a branch of computer science that focuses on building machines and software systems that can perform tasks that typically require human intelligence. AI systems are designed to learn, reason, and make decisions based on the data they are provided. They can perform a wide range of tasks, from recognizing speech and images to playing games and driving cars. AI is a rapidly growing field with significant advancements in machine learning, natural language processing, and computer vision.', token_usage=ChatTokenUsage(prompt_tokens=62, completion_tokens=93, total_tokens=155))

Complete and Streamed Responses

Call the API and get a complete response:

chat_model.get_complete_response("Who are you?")
ChatResponse(content="Hello! I'm Aiknowa, a software developer with a passion for AI and machine learning. I love exploring the potential of these technologies and finding creative ways to implement them in software applications. How can I assist you today?", token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=47, total_tokens=93))

Get a streamed response:

for response in chat_model.get_streamed_response("What is AI?"):
    print(response.content, end="", flush=True)
AI stands for Artificial Intelligence. It is a branch of computer science that focuses on creating intelligent machines that can perform tasks that normally require human intelligence. AI involves the development of algorithms and models that enable machines to learn from data, reason, and make decisions. It encompasses various subfields such as machine learning, natural language processing, computer vision, and robotics. The ultimate goal of AI is to create machines that can mimic human cognitive abilities and perform tasks autonomously.

We also support async calls.

Get a complete response asynchronously:

await chat_model.get_complete_response_async("Who are you?")
ChatResponse(content='Hello! My name is Aiknowa, and I am a software developer passionate about AI and machine learning. I love exploring the possibilities and applications of artificial intelligence in various domains. How can I assist you today?', token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=44, total_tokens=90))

Get a streamed response asynchronously:

async for response in await chat_model.get_streamed_response_async("What is AI?"):
    print(response.content, end="", flush=True)
AI stands for Artificial Intelligence. It is a branch of computer science that focuses on creating intelligent machines capable of mimicking human behavior and cognitive abilities. AI enables machines to perceive, reason, learn, and problem-solve, leading to improved decision-making and problem-solving capabilities. It encompasses various techniques like machine learning, natural language processing, computer vision, and robotics. The aim of AI is to create intelligent systems that can perform tasks autonomously, adapt to changing environments, and continuously improve their performance.

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

aiknow-0.0.3.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiknow-0.0.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file aiknow-0.0.3.tar.gz.

File metadata

  • Download URL: aiknow-0.0.3.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.0 Darwin/23.1.0

File hashes

Hashes for aiknow-0.0.3.tar.gz
Algorithm Hash digest
SHA256 10aec18f040391501a3eea0d209032862b2bc4a1c30b2c9136372691d68c0741
MD5 493b515a64e7666da7c6ec8b69b015ba
BLAKE2b-256 08dd5fd7c752857faba5455f301e2c37950ed41648cc576b9390fdc7cc905a59

See more details on using hashes here.

File details

Details for the file aiknow-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: aiknow-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.0 Darwin/23.1.0

File hashes

Hashes for aiknow-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5e1c7c45a03e7f0e104ed2178e0e11b3d60c5fc3bc730fcce127d78243d7922c
MD5 9c60274e8e46f60af738a43ebb58d435
BLAKE2b-256 38445ca048d6ac1a750c918d22370316ddb103bdf51eb3d8e27821196efd7e75

See more details on using hashes here.

Supported by

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