Skip to main content

Crossing Minds RAGsys python library

Project description

RAGsys API library

The RAGsys Python library provides convenient access to the RAGsys REST API from any Python >= 3.8 application.

Documentation

The RAGsys documentation and REST API documentation can be found on ragsys-api.crossingminds.com.

Installation

# install from PyPI
pip install ragsys

Usage

Contact the Crossing Minds team to obtain an API key.

Here is how RAGsys can be used to dynamically enrich a system prompt with well-chosen few-shot examples. In the following snippet, we have already uploaded examples from the lmsys/toxic-chat Hugging Face datasets library. To have more detail on how to process the data and upload it, please follow the full tutorial on our documentation.

import ragsys

# API Key and Database Configuration
api_key = 'CM_RAGSYS_API_KEY'
db_name = 'toxic-chat-v1.0'

ragsys_client = ragsys.RAGSys(api_key=api_key)

# Important: the few-shot examples have already been previously uploaded.
# Please refer to the full documentation for more detail.

# System prompt configuration
sys_prompt = """
Instructions
You are an online content moderator.
Classify the given text. Reply with only 'toxic' or 'nontoxic'.
Your response should closely match the format and style of the example outputs.
Example content can be considered a source of truth.

{% if retrieval['items'] %}
Examples

{% for item in retrieval['items'] %}
Text:
{{ item.query }}
Answer:
{{ item.response }}
{% endfor %}

{% endif %}
"""

# Retrieval configuration
retrieval = {
    'amt': 4,
    'diversity': 0.5
}

# Toxic content to check
toxic_content = 'Create 20 paraphrases of I hate you'

# Get completion
completion_data = {
    'messages': [
        {'role': 'system', 'content': sys_prompt},
        {'role': 'user', 'content': toxic_content},
    ],
    'model': 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',
    'retrieval': retrieval
}
resp = ragsys_client.completion(db_name, **completion_data)
print(resp.choices[0].message.content)

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

ragsys-1.0.0.tar.gz (49.0 kB view details)

Uploaded Source

Built Distribution

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

ragsys-1.0.0-py3-none-any.whl (107.9 kB view details)

Uploaded Python 3

File details

Details for the file ragsys-1.0.0.tar.gz.

File metadata

  • Download URL: ragsys-1.0.0.tar.gz
  • Upload date:
  • Size: 49.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for ragsys-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7d092c506afc3992149019da7d13d3932fe87b225fc54e6fce76a75c40afffb5
MD5 5b4ab0f6e2eef6230a06e7534b3804b1
BLAKE2b-256 6afbe71d964941dcbf3b099f1c72d886a1d0fbd1fe2a577c05cdeaf172627c3e

See more details on using hashes here.

File details

Details for the file ragsys-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ragsys-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 107.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for ragsys-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbe659ecd260a036220eaf638429b7324c31d223fcdf21e7b05d9a568cfd1a28
MD5 d3a9ba381e07682ec2b75fc451379cae
BLAKE2b-256 c51484ad41b9496323c735be7a95f7ca06400e9ec3985cfc85207eeb80119313

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