Mate-Engine/Assets/LLMUnity/Samples/FunctionCalling/FunctionCalling.cs
shinyflvre 39a7b41d7d 1.4.0 Pre Release
**Changelog 1.4.0 – THE LOCAL AI Update**

**Disclaimer:**
The AI runs *entirely locally* and is designed to be environmentally and ethically responsible.
- It does **not** harm nature or exploit any artists.
- It has only **1.5 billion parameters**, making it a **very small model** by modern standards.
- It consumes as much GPU energy as watching a **1440p 60fps YouTube video**.
- It was **not trained on artist data**; it uses personal input and public Wikipedia datasets.
- It has its own personality, and I ensured it adheres to **ethical standards**.

---

### New Features

- Added **Qwen 2.5 1.5B LLM** to MateEngine!
  - Press **Middle Mouse Button** while hovering over the pet to open the chat window.
  - Runs fully locally on your GPU — no internet connection required.
  - Only uses GPU while processing prompts.
  - Note: This is a **lightweight model** and won’t handle complex tasks or coding. It’s just a small, fun feature!

- Added **Resize Button** – Quickly adjust app size for 1080p, 1440p, and 4K monitors.

- Added **VRM Information Panel** – Displays polygon count, VRM version, and bone status:
  - **Perfect** – Properly exported model.
  - **Failure** – Model has export issues; animations may break.

- Added **Options Submenu**.
- Added **Volume Sliders** – Independently control pet, effects, and menu volume.
- Added **Graphics Settings**.
- Added **Dance Trails** – Glowing effects on the pet’s hands during dance. Toggle on/off as desired.
- Improved **Music Source Selector** – You can now whitelist or add custom audio sources for dancing.
- Added **MateEngine Version Info** – View the current app version from the menu.
- Menu can now be opened with **M** key or **Right-Click**.
- Added full support for **VRM 1.x** and **VRM 0.x** models.
- Introduced **VRM Validator Tool** in Unity Editor – Great for content creators.

---

### Improvements & Fixes

- Major **Performance Optimizations**.
- Fixed a **GC Error** that could appear after 6–12 hours of continuous use.
- Improved **Hand Tracking** – Reduced stuttering in some animations.
- Added **Discord Rich Presence** integration.
- Added **Glowing Halo** for Steam users as exclusive DLC!
2025-04-08 19:16:19 +02:00

102 lines
3.2 KiB
C#

using UnityEngine;
using LLMUnity;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Reflection;
namespace LLMUnitySamples
{
public static class Functions
{
static System.Random random = new System.Random();
public static string Weather()
{
string[] weather = new string[]{"sunny", "rainy", "cloudy", "snowy"};
return "The weather is " + weather[random.Next(weather.Length)];
}
public static string Time()
{
return "The time is " + random.Next(24).ToString("D2") + ":" + random.Next(60).ToString("D2");
}
public static string Emotion()
{
string[] emotion = new string[]{"happy", "sad", "exhilarated", "ok"};
return "I am feeling " + emotion[random.Next(emotion.Length)];
}
}
public class FunctionCalling : MonoBehaviour
{
public LLMCharacter llmCharacter;
public InputField playerText;
public Text AIText;
void Start()
{
playerText.onSubmit.AddListener(onInputFieldSubmit);
playerText.Select();
llmCharacter.grammarString = MultipleChoiceGrammar();
}
string[] GetFunctionNames()
{
List<string> functionNames = new List<string>();
foreach (var function in typeof(Functions).GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)) functionNames.Add(function.Name);
return functionNames.ToArray();
}
string MultipleChoiceGrammar()
{
return "root ::= (\"" + string.Join("\" | \"", GetFunctionNames()) + "\")";
}
string ConstructPrompt(string message)
{
string prompt = "Which of the following choices matches best the input?\n\n";
prompt += "Input:" + message + "\n\n";
prompt += "Choices:\n";
foreach(string functionName in GetFunctionNames()) prompt += $"- {functionName}\n";
prompt += "\nAnswer directly with the choice";
return prompt;
}
string CallFunction(string functionName)
{
return (string) typeof(Functions).GetMethod(functionName).Invoke(null, null);
}
async void onInputFieldSubmit(string message)
{
playerText.interactable = false;
string functionName = await llmCharacter.Chat(ConstructPrompt(message));
string result = CallFunction(functionName);
AIText.text = $"Calling {functionName}\n{result}";
playerText.interactable = true;
}
public void CancelRequests()
{
llmCharacter.CancelRequests();
}
public void ExitGame()
{
Debug.Log("Exit button clicked");
Application.Quit();
}
bool onValidateWarning = true;
void OnValidate()
{
if (onValidateWarning && !llmCharacter.remote && llmCharacter.llm != null && llmCharacter.llm.model == "")
{
Debug.LogWarning($"Please select a model in the {llmCharacter.llm.gameObject.name} GameObject!");
onValidateWarning = false;
}
}
}
}