mirror of
https://github.com/Oathbreaker-AI/api-examples.git
synced 2026-12-01 19:03:26 -10:00
* Add guides for the OpenAI SDK, LangChain, LlamaIndex and CrewAI Each guide gives the settings that point the library at Oathbreaker, a runnable example that makes one billable request, the request that example sends, and what to watch for with that library. - The examples send only the request fields the API lists, set an output budget, and switch off the libraries' automatic retries. Left at their defaults, a failed call was sent 3 times by the OpenAI SDK and LangChain, 9 times by CrewAI and 12 times by LlamaIndex. - Each example has a test that runs it against a local stand-in server. The test fails if the request carries a field the API does not list, or if a failed request is sent more than once. A CI job runs the test for each library from its pinned requirements. - The main README names both public models and lists the base URL, authentication and what the API does not offer. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01CfDjYvdXHyHmrgmoTbM2FU * Run the framework tests on Python 3.12 The runner's own Python is 3.14, which CrewAI 1.15.41 does not install on. The framework job now sets Python 3.12, the version the examples were checked with, and the CrewAI guide says which versions work. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01CfDjYvdXHyHmrgmoTbM2FU --------- Co-authored-by: Claude <[email protected]>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""LangChain pointed at Oathbreaker. Run on your server; keep keys private."""
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
from langchain_openai import ChatOpenAI
|
|
from openai import APIStatusError, OpenAIError
|
|
|
|
BASE_URL = "https://oathbreaker.ai/v1"
|
|
MODEL = "oathbreaker-glm-5.3"
|
|
|
|
|
|
def complete(api_key, base_url=BASE_URL):
|
|
if not api_key:
|
|
raise ValueError("Set OATHBREAKER_API_KEY in your environment.")
|
|
# max_retries=0: left at its default, ChatOpenAI repeats a failed request on its own.
|
|
llm = ChatOpenAI(
|
|
model=MODEL,
|
|
api_key=api_key,
|
|
base_url=base_url,
|
|
max_tokens=2048,
|
|
reasoning_effort="low",
|
|
timeout=650,
|
|
max_retries=0,
|
|
)
|
|
try:
|
|
message = llm.invoke("Reply with exactly: Oathbreaker connected.")
|
|
except APIStatusError as error:
|
|
raise RuntimeError(f"API returned HTTP {error.status_code}. Inspect your dashboard before retrying.") from None
|
|
if message.response_metadata.get("finish_reason") != "stop" or not message.content:
|
|
raise RuntimeError("No complete text answer. Inspect usage and the output budget before retrying.")
|
|
return {"text": message.content, "usage": message.usage_metadata}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
result = complete(os.environ.get("OATHBREAKER_API_KEY"))
|
|
print(result["text"])
|
|
print("Usage:", json.dumps(result["usage"]))
|
|
except (ValueError, RuntimeError, OpenAIError) as error:
|
|
print(str(error), file=sys.stderr)
|
|
sys.exit(1)
|