Skip to main content

A Python toolkit for advanced data processing and API interactions

Project description

descartcan

LLM

Step1, llm_config.yaml

openai:
  keys:
    - name: "openai_key1"
      api_key: "XXX"
  models:
    gpt4: "gpt-4-0125-preview"
    gpt40: "gpt-4o"

bedrock:
  keys:
    - name: "bedrock"
      api_key: "XXX"
      api_secret: "XXXXX"
  models:
      haiku35: "us.anthropic.claude-3-5-haiku-20241022-v1:0"

Step2, load models

from descartcan.llm.factory import LLModelFactory
model_factory = LLModelFactory.from_config(config="llm_config.yaml")
model = model_factory.get_model("openai.gpt4")

# 单轮对话
response = await model.chat(
    question="Show Python",
    system="你是一个编程专家"
)
print(f"回复: {response.content}")
print(f"Token统计: 提示词{response.prompt_tokens}, 生成{response.completion_tokens}, 总计{response.total_tokens}")

# 多轮对话
history = [
    {"role": "user", "content": "Python和Java的区别是什么?"},
    {"role": "assistant", "content": "Python和Java有以下主要区别:..."}
]
response = await model.chat(
    question="哪个更适合初学者?",
    system="你是一个编程专家",
    history=history
)
print(f"多轮对话回复: {response.content}")

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

descartcan-2025.8.9.4.tar.gz (49.8 kB view details)

Uploaded Source

Built Distribution

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

descartcan-2025.8.9.4-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

Details for the file descartcan-2025.8.9.4.tar.gz.

File metadata

  • Download URL: descartcan-2025.8.9.4.tar.gz
  • Upload date:
  • Size: 49.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for descartcan-2025.8.9.4.tar.gz
Algorithm Hash digest
SHA256 7872132f280c37e5e72a40a98e398bda4ffaa0d8cb1b7acd8e95dbea5dd77ae7
MD5 f35d0edd6f1a21db77bde701171bac02
BLAKE2b-256 e123871d92a15859fa51d468bf08d0ad4928f3d83a19eb8a1e64bb98432dd2ff

See more details on using hashes here.

File details

Details for the file descartcan-2025.8.9.4-py3-none-any.whl.

File metadata

File hashes

Hashes for descartcan-2025.8.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 126cdeda969a019fed24bcb7775beeca9a35a511ef6a29f5dbcde22a80a741bb
MD5 36f026892e1bf635bafdc0113c2dd0d9
BLAKE2b-256 a3654becd03e5c0fe6ddd1fdf5c7dd68078dc2c008b15e1369db407ea4d09583

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