Created
July 15, 2025 05:54
-
-
Save AIAnytime/7c6a3e33872b81f1ae664987e0da4d72 to your computer and use it in GitHub Desktop.
OpenLLMetry Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dotenv import load_dotenv | |
| from openai import OpenAI | |
| from traceloop.sdk import Traceloop | |
| from traceloop.sdk.decorators import workflow, task | |
| import os | |
| load_dotenv() | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| TRACeloop_API_KEY = os.getenv("TRACeloop_API_KEY") | |
| Traceloop.init( | |
| disable_batch=True, | |
| api_key=TRACeloop_API_KEY | |
| ) | |
| client = OpenAI() | |
| @task(name="translate_hi2en") | |
| def translate_hindi(hindi_text: str) -> str: | |
| response = client.responses.create( | |
| model="gpt-4o-mini", | |
| input="Translate this Hindi text to English: " + hindi_text | |
| ) | |
| return response.output_text | |
| @task(name="translate_en2hi") | |
| def translate_english(english_text: str) -> str: | |
| response = client.responses.create( | |
| model="gpt-4o-mini", | |
| input="Translate this English text to Hindi: " + english_text | |
| ) | |
| return response.output_text | |
| @workflow(name="translate") | |
| def translate(hindi_text: str) -> tuple[str, str]: | |
| english_text = translate_hindi(hindi_text) | |
| regenerated_hindi_text = translate_english(english_text) | |
| return english_text, regenerated_hindi_text | |
| def main(): | |
| hindi_text = "आज का मौसम कैसा है?" | |
| english_text, regenerated_hindi_text = translate(hindi_text) | |
| print(f"{hindi_text} -> {english_text} -> {regenerated_hindi_text}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment