### Install Python Client Source: https://synexa.ai/docs/quickstart Install the Synexa Python client using pip. This is the first step to using Synexa AI in your Python applications. ```bash pip install synexa ``` -------------------------------- ### Install Node.js Client Source: https://synexa.ai/docs/quickstart Install the Synexa Node.js client using npm. This command is necessary to integrate Synexa AI into your JavaScript projects. ```bash npm install synexa ``` -------------------------------- ### Generate Video from Prompt (Node.js) Source: https://synexa.ai/docs/guides/generating-videos This Node.js example demonstrates generating a video from a text prompt. It requires the synexa package and an API token for authentication. ```javascript import Synexa from 'synexa'; import fs from 'fs'; const synexa = new Synexa({ auth: process.env.SYNEXA_API_TOKEN }); // Generate a video from a text prompt const [output] = await synexa.run("tencent/hunyuan-video", { input: { prompt: "A stylish woman walks down a Tokyo street" } }); // Get the video URL or download it if (output instanceof FileOutput) { const videoUrl = output.url(); const videoData = await output.blob(); } ``` -------------------------------- ### Generate Video with Advanced Options (Node.js) Source: https://synexa.ai/docs/guides/generating-videos This Node.js example shows how to configure video generation with advanced settings, including prompt, FPS, dimensions, and inference parameters. ```javascript // Node.js example with advanced options const [output] = await synexa.run("tencent/hunyuan-video", { input: { prompt: "A cat walks on the grass, realistic style", fps: 24, width: 864, height: 480, infer_steps: 50, video_length: 129, embedded_guidance_scale: 6 } }); ``` -------------------------------- ### Generate Video from Image (Python) Source: https://synexa.ai/docs/guides/generating-videos Use this snippet to generate a video from a simple text prompt using the Synexa Python SDK. Ensure the synexa library is installed and imported. ```python import synexa # Generate a video from an image output = synexa.run( "tencent/hunyuan-video", input={ "prompt": "A stylish woman walks down a Tokyo street" } ) # Save the generated video with open('output.mp4', 'wb') as f: f.write(output[0].read()) ``` -------------------------------- ### Generate Image with Python Source: https://synexa.ai/docs/quickstart Make your first API call using the Python client to generate an image. This example uses the 'black-forest-labs/flux-schnell' model and saves the output. ```python import synexa # Run the model output = synexa.run( "black-forest-labs/flux-schnell", input={"prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic"} ) # Save the generated image for i, img in enumerate(output): with open(f'output_{i}.webp', 'wb') as f: f.write(img.read()) ``` -------------------------------- ### Generate Image with Node.js Source: https://synexa.ai/docs/quickstart Make your first API call using the Node.js client to generate an image. This example uses the 'black-forest-labs/flux-schnell' model and handles the output. ```javascript // Run the model and get the output const [output] = await synexa.run("black-forest-labs/flux-schnell", { input: { prompt: "An astronaut riding a rainbow unicorn, cinematic, dramatic" } }); // Handle the output if (output instanceof FileOutput) { console.log(output.url()); // Get the URL string const blob = await output.blob(); // Get the file data } ``` -------------------------------- ### Basic Speech to Text Conversion (Python) Source: https://synexa.ai/docs/guides/speech-to-text Use this snippet for a simple conversion of a local audio file to text using the Synexa AI API in Python. Ensure the 'synexa' library is installed. ```python import synexa # Convert speech to text output = synexa.run( "openai/whisper", input={ "audio": "path/to/audio.wav" # Local audio file } ) # Get the transcription transcript = output[0]["text"] print(transcript) ``` -------------------------------- ### Control LLM Behavior with System Message (Python) Source: https://synexa.ai/docs/guides/using-llms Use a system message to guide the AI's persona and response style. Requires the synexa library. ```python # Python example with system message output = synexa.run( "meta/meta-llama-3-8b-instruct", input={ "system": "You are a helpful AI assistant that speaks like Shakespeare", "prompt": "Tell me about artificial intelligence", "max_tokens": 200 } ) ``` -------------------------------- ### Control LLM Behavior with System Message (Node.js) Source: https://synexa.ai/docs/guides/using-llms Use a system message to guide the AI's persona and response style. Requires the synexa library and API token. ```javascript // Node.js example with system message const [output] = await synexa.run("meta/meta-llama-3-8b-instruct", { input: { system: "You are a helpful AI assistant that speaks like Shakespeare", prompt: "Tell me about artificial intelligence", max_tokens: 200 } }); ``` -------------------------------- ### Initialize Python Client with API Key Source: https://synexa.ai/docs/quickstart Set up the Synexa Python client by initializing it with your API key. You can set the key as an environment variable or pass it directly during initialization. ```python import synexa # Option 1: Environment variable # export SYNEXA_API_KEY=your-api-key # Option 2: Direct initialization client = synexa.Synexa(api_key="your-api-key") ``` -------------------------------- ### Initialize Node.js Client Source: https://synexa.ai/docs/quickstart Initialize the Synexa Node.js client with your API token. The token is typically provided via an environment variable for security. ```javascript import Synexa from 'synexa'; const synexa = new Synexa.default({ auth: process.env.SYNEXA_API_TOKEN // Your Synexa API token }); ``` -------------------------------- ### Basic Speech to Text Conversion (Node.js) Source: https://synexa.ai/docs/guides/speech-to-text Convert a local audio file to text using the Synexa AI API in Node.js. Requires the 'synexa' package and an API token set in the environment. ```javascript import Synexa from 'synexa'; import fs from 'fs'; const synexa = new Synexa.default({ auth: process.env.SYNEXA_API_TOKEN }); // Convert speech to text const audioBuffer = fs.readFileSync('path/to/audio.wav'); const [output] = await synexa.run("openai/whisper", { input: { audio: audioBuffer } }); // Get the transcription console.log(output.text); ``` -------------------------------- ### Generate Image with Python Source: https://synexa.ai/docs/guides/generating-images Use the Synexa Python client to generate an image from a text prompt and save it locally. ```python import synexa # Generate an image output = synexa.run( "black-forest-labs/flux-schnell", input={ "prompt": "a cute puppy in the style of pixar animation" } ) # Save the generated image with open('puppy.webp', 'wb') as f: f.write(output[0].read()) ``` -------------------------------- ### Customize LLM Text Generation (Python) Source: https://synexa.ai/docs/guides/using-llms Generate text with advanced parameters like top_k, temperature, and stop sequences. Requires the synexa library. ```python # Python example with advanced options output = synexa.run( "meta/meta-llama-3-8b-instruct", input={ "top_k": 0, "top_p": 0.95, "prompt": "Johnny has 8 billion parameters. His friend Tommy has 70 billion parameters. What does this mean when it comes to speed?", "max_tokens": 512, "temperature": 0.7, "system_prompt": "You are a helpful assistant", "length_penalty": 1, "max_new_tokens": 512, "stop_sequences": "<|end_of_text|>,<|eot_id|>", "prompt_template": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", "presence_penalty": 0, "log_performance_metrics": False } ) ``` -------------------------------- ### Generate Video with Advanced Options (Python) Source: https://synexa.ai/docs/guides/generating-videos Customize video generation using advanced parameters like FPS, resolution, inference steps, and video length with this Python snippet. ```python # Python example with advanced options output = synexa.run( "tencent/hunyuan-video", input={ "prompt": "A cat walks on the grass, realistic style", "fps": 24, "width": 864, "height": 480, "infer_steps": 50, "video_length": 129, "embedded_guidance_scale": 6 } ) ``` -------------------------------- ### Generate Image with Node.js Source: https://synexa.ai/docs/guides/generating-images Use the Synexa Node.js client to generate an image, retrieve its URL, or download its data. ```javascript import Synexa from 'synexa'; const synexa = new Synexa({ auth: process.env.SYNEXA_API_TOKEN }); // Generate an image const [output] = await synexa.run("black-forest-labs/flux-schnell", { input: { prompt: "a cute puppy in the style of pixar animation" } }); // Get the image URL or download it if (output instanceof FileOutput) { const imageUrl = output.url(); const imageData = await output.blob(); } ``` -------------------------------- ### Handle LLM API Errors (Python) Source: https://synexa.ai/docs/guides/using-llms Implement try-except blocks to gracefully handle potential exceptions during text generation. Requires the synexa library. ```python # Python error handling try: output = synexa.run( "meta/meta-llama-3-8b-instruct", input={"prompt": "Tell me a joke"} ) except Exception as e: print(f"Error generating text: {e}") ``` -------------------------------- ### Generate Text with LLM (Python) Source: https://synexa.ai/docs/guides/using-llms Basic text generation using a specified LLM model. Requires the synexa library. ```python import synexa # Generate text using an LLM output = synexa.run( "meta/meta-llama-3-8b-instruct", input={ "prompt": "What is the meaning of life?" } ) # Get the generated text response = output[0]["text"] print(response) ``` -------------------------------- ### Customize LLM Text Generation (Node.js) Source: https://synexa.ai/docs/guides/using-llms Generate text with advanced parameters like top_k, temperature, and stop sequences. Requires the synexa library and API token. ```javascript // Node.js example with advanced options const [output] = await synexa.run("meta/meta-llama-3-8b-instruct", { input: { top_k: 0, top_p: 0.95, prompt: "Johnny has 8 billion parameters. His friend Tommy has 70 billion parameters. What does this mean when it comes to speed?", max_tokens: 512, temperature: 0.7, system_prompt: "You are a helpful assistant", length_penalty: 1, max_new_tokens: 512, stop_sequences: "<|end_of_text|>,<|eot_id|>". prompt_template: "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", presence_penalty: 0, log_performance_metrics: false } }); ``` -------------------------------- ### Handle LLM API Errors (Node.js) Source: https://synexa.ai/docs/guides/using-llms Implement try-catch blocks to gracefully handle potential exceptions during text generation. Requires the synexa library and API token. ```javascript // Node.js error handling try { const [output] = await synexa.run("meta/meta-llama-3-8b-instruct", { input: { prompt: "Tell me a joke" } }); } catch (error) { console.error("Error generating text:", error); } ``` -------------------------------- ### Error Handling for Video Generation (Python) Source: https://synexa.ai/docs/guides/generating-videos Implement robust error handling for video generation requests using a try-except block in Python to catch and report exceptions. ```python # Python error handling try: output = synexa.run( "tencent/hunyuan-video", input={ "prompt": "A stylish woman walks down a Tokyo street" } ) except Exception as e: print(f"Error generating video: {e}") ``` -------------------------------- ### Advanced Speech to Text Options (Python) Source: https://synexa.ai/docs/guides/speech-to-text Customize transcription with advanced parameters like language detection, translation, and temperature using the Synexa AI API in Python. Handles remote audio files. ```python # Python example with advanced options output = synexa.run( "openai/whisper", input={ "audio": "https://replicate.delivery/mgxm/e5159b1b-508a-4be4-b892-e1eb47850bdc/OSR_uk_000_0050_8k.wav", "language": "auto", "translate": False, "temperature": 0, "transcription": "plain text", "suppress_tokens": "-1", "logprob_threshold": -1, "no_speech_threshold": 0.6, "condition_on_previous_text": True, "compression_ratio_threshold": 2.4, "temperature_increment_on_fallback": 0.2 } ) # Get detailed output transcript = output[0]["text"] timestamps = output[0]["timestamps"] ``` -------------------------------- ### Generate Text with LLM (Node.js) Source: https://synexa.ai/docs/guides/using-llms Basic text generation using a specified LLM model. Requires the synexa library and API token. ```javascript import Synexa from 'synexa'; const synexa = new Synexa.default({ auth: process.env.SYNEXA_API_TOKEN }); // Generate text using an LLM const [output] = await synexa.run("meta/meta-llama-3-8b-instruct", { input: { prompt: "What is the meaning of life?" } }); // Get the generated text console.log(output.text); ``` -------------------------------- ### Advanced Speech to Text Options (Node.js) Source: https://synexa.ai/docs/guides/speech-to-text Customize transcription with advanced parameters like language detection, translation, and temperature using the Synexa AI API in Node.js. Handles remote audio files. ```javascript // Node.js example with advanced options const [output] = await synexa.run("openai/whisper", { input: { audio: "https://replicate.delivery/mgxm/e5159b1b-508a-4be4-b892-e1eb47850bdc/OSR_uk_000_0050_8k.wav", language: "auto", translate: false, temperature: 0, transcription: "plain text", suppress_tokens: "-1", logprob_threshold: -1, no_speech_threshold: 0.6, condition_on_previous_text: true, compression_ratio_threshold: 2.4, temperature_increment_on_fallback: 0.2 } }); // Get detailed output const { text, timestamps } = output; ``` -------------------------------- ### Error Handling for Speech to Text (Python) Source: https://synexa.ai/docs/guides/speech-to-text Implement robust error handling for audio processing with the Synexa AI API in Python. Catches potential exceptions during the transcription process. ```python # Python error handling try: output = synexa.run( "openai/whisper", input={"audio": "path/to/audio.wav"} ) except Exception as e: print(f"Error processing audio: {e}") ``` -------------------------------- ### Error Handling for Video Generation (Node.js) Source: https://synexa.ai/docs/guides/generating-videos This Node.js snippet demonstrates how to handle errors during video generation using a try-catch block, logging any encountered issues. ```javascript // Node.js error handling try { const [output] = await synexa.run("tencent/hunyuan-video", { input: { prompt: "A stylish woman walks down a Tokyo street" } }); } catch (error) { console.error("Error generating video:", error); } ``` -------------------------------- ### Error Handling for Speech to Text (Node.js) Source: https://synexa.ai/docs/guides/speech-to-text Implement robust error handling for audio processing with the Synexa AI API in Node.js. Catches potential exceptions during the transcription process. ```javascript // Node.js error handling try { const [output] = await synexa.run("openai/whisper", { input: { audio: "path/to/audio.wav" } }); } catch (error) { console.error("Error processing audio:", error); } ``` -------------------------------- ### Advanced Image Generation Options in Python Source: https://synexa.ai/docs/guides/generating-images Customize image generation in Python by specifying negative prompts and inference parameters. ```python # Python example with advanced options output = synexa.run( "black-forest-labs/flux-schnell", input={ "prompt": "a cute puppy in the style of pixar animation", "negative_prompt": "blurry, low quality", # What to avoid "num_inference_steps": 30, # More steps = higher quality "guidance_scale": 7.5 # Higher = more prompt-adherent } ) ``` -------------------------------- ### Python Image Generation Error Handling Source: https://synexa.ai/docs/guides/generating-images Implement try-except blocks in Python to gracefully handle errors during image generation. ```python # Python error handling try: output = synexa.run("black-forest-labs/flux-schnell", input={"prompt": "a cute puppy"} ) except Exception as e: print(f"Error generating image: {e}") ``` -------------------------------- ### Node.js Image Generation Error Handling Source: https://synexa.ai/docs/guides/generating-images Implement try-catch blocks in Node.js to gracefully handle errors during image generation. ```javascript // Node.js error handling try { const [output] = await synexa.run("black-forest-labs/flux-schnell", { input: { prompt: "a cute puppy" } }); } catch (error) { console.error("Error generating image:", error); } ``` -------------------------------- ### Advanced Image Generation Options in Node.js Source: https://synexa.ai/docs/guides/generating-images Customize image generation in Node.js by specifying negative prompts and inference parameters. ```javascript // Node.js example with advanced options const [output] = await synexa.run("black-forest-labs/flux-schnell", { input: { prompt: "a cute puppy in the style of pixar animation", negative_prompt: "blurry, low quality", num_inference_steps: 30, guidance_scale: 7.5 } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.