Skip to content

Latest commit

ย 

History

History
86 lines (62 loc) ยท 2.83 KB

File metadata and controls

86 lines (62 loc) ยท 2.83 KB

Groq Unity API Support Library ๐Ÿš€

License Version

๐Ÿ’ก Introduction

This community maintained library simplifies the integration of Groq API functionalities into Unity projects, making it easier for developers to utilize Groq's powerful capabilities within the Unity environment. The current focus is on providing streamlined access to Groq's Chat Completion functionality ๐Ÿ—จ๏ธ, with plans to support additional features in the future.

โœ… Current Features

  • Groq Chat Completion: Integrate AI-driven chat functionality into your Unity projects. Perfect for dialogue systems, NPC interactions, or any scenario requiring natural language processing.

๐Ÿ”ฎ Upcoming Features

We are actively working on expanding the library to support additional Groq API features, including:

  • Streaming Chat Completion: Real-time chat completion to support dynamic conversational experiences โณ.
  • Audio Translation: Convert spoken language into another language directly within Unity ๐ŸŒ.
  • Audio Transcription: Transform speech into text for in-game narration, commands, or dialogue transcription ๐ŸŽค๐Ÿ“.

๐Ÿ“ฆ Installation

To use this library in your unity project:

  • Clone this repository or download the GroqApiClient.cs file.
  • Add the file to your project.
  • Ensure your project has the Newtonsoft.Json library.

๐Ÿš€ Getting Started

Here's a simple example to get you started:

using UnityEngine;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using GroqApiLibrary;

public class GroqApiUnity : MonoBehaviour
{
    private string apiKey = "YOUR_API_KEY";  
    private GroqApiClient groqApi;

    void Start()
    {
        groqApi = new GroqApiClient(apiKey);

        string exampleMessage = "Hello, how are you?";
        OnSubmit(exampleMessage);  
    }

    public async void OnSubmit(string userMessage)
    {
        if (!string.IsNullOrEmpty(userMessage))
        {
            var request = new JObject
            {
                ["model"] = "llama3-8b-8192",
                ["temperature"] = 0.5,
                ["max_tokens"] = 100,
                ["top_p"] = 1,
                ["messages"] = new JArray
                {
                    new JObject { ["role"] = "user", ["content"] = userMessage }
                }
            };

            await GetChatCompletion(request);
        }
    }

    private async Task GetChatCompletion(JObject request)
    {
        var result = await groqApi.CreateChatCompletionAsync(request);
        var response = result?["choices"]?[0]?["message"]?["content"]?.ToString() ?? "No response found";

        Debug.Log(response);
    }
}

๐Ÿ“„ License

This library is licensed under the MIT License. See the LICENSE file for details.