同步完整源码 - 2026-05-25

This commit is contained in:
xiaoxue
2026-05-25 01:45:55 +08:00
commit af7cdc0ffd
1581 changed files with 225877 additions and 0 deletions
@@ -0,0 +1,47 @@
import os
import agentops
from haystack.components.generators.chat import AzureOpenAIChatGenerator
def main():
agentops.init(os.getenv("AGENTOPS_API_KEY"))
if not os.getenv("AZURE_OPENAI_API_KEY") or not os.getenv("AZURE_OPENAI_ENDPOINT"):
print("Skipping Azure example: missing AZURE_OPENAI_API_KEY or AZURE_OPENAI_ENDPOINT (CI-safe skip)")
return
tracer = agentops.start_trace(
trace_name="Haystack Azure Chat Example",
tags=["haystack", "azure", "chat", "agentops-example"],
)
api_version = os.getenv("AZURE_OPENAI_API_VERSION", "2024-06-01")
deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT", "gpt-4o-mini")
generator = AzureOpenAIChatGenerator(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version=api_version,
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
deployment_name=deployment,
)
messages = [{"role": "user", "content": "In one sentence, what is AgentOps?"}]
result = generator.run(messages=messages)
replies = result.get("replies") or []
print("Haystack Azure reply:", replies[0] if replies else "<no reply>")
print("\n" + "=" * 50)
print("Now let's verify that our LLM calls were tracked properly...")
try:
validation_result = agentops.validate_trace_spans(trace_context=tracer)
agentops.print_validation_summary(validation_result)
except agentops.ValidationError as e:
print(f"\n❌ Error validating spans: {e}")
raise
agentops.end_trace(tracer, end_state="Success")
if __name__ == "__main__":
main()
+38
View File
@@ -0,0 +1,38 @@
import os
import agentops
from haystack.components.generators.openai import OpenAIGenerator
def main():
agentops.init(os.getenv("AGENTOPS_API_KEY"))
if not os.getenv("OPENAI_API_KEY"):
print("Skipping OpenAI example: missing OPENAI_API_KEY")
return
tracer = agentops.start_trace(
trace_name="Haystack OpenAI Example",
tags=["haystack", "openai", "agentops-example"],
)
prompt = "In one sentence, what is AgentOps?"
generator = OpenAIGenerator(model="gpt-4o-mini")
result = generator.run(prompt=prompt)
replies = result.get("replies") or []
print("Haystack reply:", replies[0] if replies else "<no reply>")
print("\n" + "=" * 50)
print("Now let's verify that our LLM calls were tracked properly with AgentOps...")
try:
validation_result = agentops.validate_trace_spans(trace_context=tracer)
agentops.print_validation_summary(validation_result)
except agentops.ValidationError as e:
print(f"\n❌ Error validating spans: {e}")
raise
agentops.end_trace(tracer, end_state="Success")
if __name__ == "__main__":
main()
+2
View File
@@ -0,0 +1,2 @@
haystack-ai>=2.0.0
openai>=1.102.0