Skip to main content

Client for AICosmos

This package implements the client for AICosmos. Before using this package, please make sure that you have a valid account for AICosmos.

Login & Create Session

By using this client, you can chat with our backend in "base" mode. To login, you will need the server's address and your API key. Our conversation system is based on sessions, you can either start a new session, or continue with an existing one.

from aicosmos_client.client import AICosmosClient 

# Login
client = AICosmosClient(
    base_url="https://aicosmos.ai/api", api_key="xxx"
)

# Create a new session
try:
    new_session_id = client.create_session()
except Exception as e:
    print(f"Error creating new session: {e}")
    exit(0)

# Check all existing sessions
try:
    my_sessions = client.get_my_sessions()
except Exception as e:
    print(f"Error getting my sessions: {e}")
    exit(0)
# [{"session_id", "title"}, ...]
print(my_sessions)

Chatting

Our framework is different from "chat completions", where you give an llm the conversation history. Instead, your conversation history, along with other tool execution results, are stored in our database. This gives you a clean and simple interface to use, without worrying about constructing complicated contexts. The following code starts a new conversation in "base" mode. We support both stream and non-stream responses.

Non-Stream Response

In this case, you only need to submit your prompt. The whole conversation history is returned.

# prompt = "Hello"
try:
    conversation_history = client.chat(session_id, prompt)
except Exception as e:
    print(f"Error chatting: {e}")
    exit(0)
print(conversation_history)

Stream Response

In this scenario, our server only returns the diff between current history and old history. There are two types of diffs:

  • added: a new item is added into conversation history
  • updated: certain fields of existing history has changed

The diffs are very intuitive. You can track the conversation history dinamically using them:

# get existing conversation history
tracked_history = client.get_session_history(session)

for diff in client.chat_stream(
    session_id,
    prompt,
):
    # add new items
    for add in diff["added"]:
        index = add["index"]
        item = add["item"]
        tracked_history.append(item)
    # update existing items
    for update in diff["updated"]:
        index = update["index"]
        field = update["field"]
        # new_suffix is a string
        new_suffix = update["new_suffix"]
        if field in tracked_history[index].keys():
            tracked_history[index][field] += new_suffix
        else:
            tracked_history[index] = new_suffix

# now `tracked_history` is up to date!

File Upload & Download

To upload a file to current session, just provide session id and local file path:

client.upload_file(session_id, "./my_file.txt")

To download an uploaded file, just provide session id, filename and where you want to save it.

client.download_file(session_id, "my_file.txt", "./my_local_path.txt")

Other Modes

Apart from "base" mode, we also support "code" mode and "lean" mode. In these modes, we provide you with a web code editor, which you can open and interact with your web browser.

try:
    conversation_history = client.chat(
        new_session_id, "De Morgan's law. Start now.", mode="lean"
    )
except Exception as e:
    print(f"Error chatting: {e}")
    exit(0)
print(conversation_history)

# open this link with your web browser (e.g. Edge, Chrome)
url = client.get_browser_url(new_session_id)
print(url)

Metadata

Release files for aicosmos-client 0.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aicosmos-client 0.0.16
File Size Uploaded Provenance
aicosmos_client-0.0.16.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aicosmos-client 0.0.16
File Interpreter ABI Platform
aicosmos_client-0.0.16-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / aicosmos_client-0.0.16.tar.gz

Download URL aicosmos_client-0.0.16.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1c51a2213318ff7bf4a114e56837dbecb51522b6f24de81f9aca859d688d2bad
BLAKE2b-256 checksum
How to use checksums
e1ee2e1f7fcd4acc5a131e85701b42672109c6bbae3fce4a0b4686a79826eb55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / aicosmos_client-0.0.16-py3-none-any.whl

Download URL aicosmos_client-0.0.16-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f8b569b564d4d9872b46495bc0c8e977a0cfbb488310ceeda6cd170f0786da9
BLAKE2b-256 checksum
How to use checksums
572ad319bbc093f2f90a65f790ce2b924628689f0b4118e26cff898ca88d8b34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Security for aicosmos-client 0.0.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page