Skip to main content

TruthStack supplement safety API SDK. LangChain, LlamaIndex, CrewAI, and OpenAI integrations.

Project description

truthstack

Python SDK for TruthStack supplement safety API. Works with LangChain, LlamaIndex, CrewAI, OpenAI function calling, and standalone.

Install

pip install truthstack                    # Core client (zero deps)
pip install truthstack[langchain]         # + LangChain tools
pip install truthstack[llamaindex]        # + LlamaIndex tools
pip install truthstack[crewai]            # + CrewAI tools
pip install truthstack[all]              # Everything

Quick Start

Standalone

from truthstack import TruthStackClient

client = TruthStackClient(api_key="your-key")

# Check interactions (the money endpoint)
result = client.check_interactions(
    supplements=["berberine", "magnesium", "vitamin_d"],
    medications=["semaglutide"]
)
print(result["risk_level"])  # "HIGH"
print(result["cyp_pathway_conflicts"])
print(result["evidence_by_compound"])

# Get evidence balance
evidence = client.get_evidence("berberine")
print(evidence["evidence_balance"])  # {"positive": 8, "null": 2, ...}
print(evidence["citations"])  # [{"pmid": "12345", ...}]

LangChain

from truthstack import get_langchain_tools
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent

tools = get_langchain_tools(api_key="your-key")
llm = ChatOpenAI(model="gpt-4")
agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

result = executor.invoke({"input": "Can I take berberine while on Ozempic?"})

LlamaIndex

from truthstack import get_llamaindex_tools
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

tools = get_llamaindex_tools(api_key="your-key")
agent = ReActAgent.from_tools(tools, llm=OpenAI(model="gpt-4"))

response = agent.chat("What's the evidence for CoQ10?")

CrewAI

from truthstack import get_crewai_tools
from crewai import Agent, Task, Crew

tools = get_crewai_tools(api_key="your-key")

analyst = Agent(
    role="Supplement Safety Analyst",
    goal="Check supplement interactions and evidence",
    tools=tools,
)

OpenAI Function Calling

from truthstack import get_openai_functions, handle_openai_function_call
from openai import OpenAI

client = OpenAI()
functions = get_openai_functions()

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Is magnesium safe with sertraline?"}],
    functions=functions,
    function_call="auto",
)

call = response.choices[0].message.function_call
result = handle_openai_function_call(
    call.name, json.loads(call.arguments), api_key="your-key"
)

System Prompts

from truthstack import SYSTEM_PROMPTS

SYSTEM_PROMPTS["supplement_safety_advisor"]   # General safety
SYSTEM_PROMPTS["glp1_supplement_checker"]     # GLP-1/Ozempic focus
SYSTEM_PROMPTS["evidence_researcher"]         # Research analysis
SYSTEM_PROMPTS["stack_optimizer"]             # Stack optimization
SYSTEM_PROMPTS["clinician_assistant"]         # Clinician-facing

Tools

Tool Description
truthstack_check_interactions Check supplement + drug interactions
truthstack_get_evidence Evidence balance + citations
truthstack_search_supplements Fuzzy compound search
truthstack_safety_signals FDA CAERS/FAERS signals
truthstack_drug_profile Drug CYP450 + botanical interactions

Environment Variables

TRUTHSTACK_API_KEY=your-key
TRUTHSTACK_BASE_URL=https://api.truthstack.co  # optional

API Key

Get a free key (2,000 calls/month) at truthstack.co/developers.

License

MIT

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

truthstack-1.0.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

truthstack-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: truthstack-1.0.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for truthstack-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f3228563170abd55e5eb89d45515f0f0103337b85bb7e85099bf5931f72f0f5b
MD5 0e89466d771f7f574dc8d1d98e87f7b9
BLAKE2b-256 c721fecfa1d5eca853f495a4a8cef96ac7a41d281f1f1ce38392fb2eef93e932

See more details on using hashes here.

File details

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

File metadata

  • Download URL: truthstack-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for truthstack-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26977162158700c3e2e2f2a73711d671a9a9ec92c102c5c7a87aacc9a2fa01c2
MD5 e25928864cbebaa70eac8e982576a9bb
BLAKE2b-256 8746c84cde0def49a6ed706a8689f58ddc35e84537dc6961130ed567eeabecc7

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