Skip to content

Commit 157fd94

Browse files
committed
Added project files.
1 parent b6a26fc commit 157fd94

File tree

77 files changed

+1848
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1848
-90
lines changed

.github/workflows/upm-subtree-split.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919

2020
- uses: RageAgainstThePixel/upm-subtree-split@v1.1
2121
with:
22-
package-root: "**/Packages/com.uralstech.package-name"
22+
package-root: "**/Packages/com.uralstech.uai.abstraction"

Documentation/DocSource/QuickStart.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,103 @@ Please note that the code provided in this page is *purely* for learning purpose
44

55
## Breaking Changes Notice
66

7-
If you've just updated the package, it is recommended to check the [*changelogs*](https://github.com/Uralstech/PackageName/releases) for information on breaking changes.
7+
If you've just updated the package, it is recommended to check the [*changelogs*](https://github.com/Uralstech/UAI.Abstraction/releases) for information on breaking changes.
8+
9+
## Setup
10+
11+
This plugin only provides abstraction for the chat completion APIs provided by *other* third party libraries. The plugin itself does not contain the code to interact with
12+
the Gemini or GPT APIs. The Gemini client relies on [*UGemini*](https://uralstech.github.io/UGemini/), and the OpenAI client relies on
13+
[*com.openai.unity*](https://rageagainstthepixel.github.io/OpenAI-DotNet/).
14+
15+
Authentication is also handled by the third party libraries. See [*UGemini: Setup*](https://uralstech.github.io/UGemini/DocSource/QuickStart.html#setup) and
16+
[*com.openai.unity: Authentication*](https://rageagainstthepixel.github.io/OpenAI-DotNet/README.html#authentication)
17+
18+
Now you can create an instance of the desired API client. For Gemini:
19+
20+
```csharp
21+
using Uralstech.UAI.Abstraction;
22+
using Uralstech.UAI.Abstraction.Providers.Gemini;
23+
24+
IModelClient client = new GeminiModelClient();
25+
```
26+
27+
For OpenAI:
28+
29+
```csharp
30+
using Uralstech.UAI.Abstraction;
31+
using Uralstech.UAI.Abstraction.Providers.OAI;
32+
33+
IModelClient client = new OAIModelClient();
34+
```
35+
36+
## Chat
37+
38+
You can chat with the model using [`IModelClient.Chat`](~/api/Uralstech.UAI.Abstraction.IModelClient.yml#Uralstech_UAI_Abstraction_IModelClient_Chat_System_Collections_Generic_IReadOnlyList_Uralstech_UAI_Abstraction_Message__System_String_System_Boolean_System_Threading_CancellationToken_).
39+
40+
```csharp
41+
using Uralstech.UAI.Abstraction.Chat;
42+
43+
ChatInferenceResult result = await client.Chat(new Message[]
44+
{
45+
new Message(Role.System, "You are a helpful, friendly assistant."),
46+
new Message(Role.User, "What is the capital of India?")
47+
});
48+
49+
Debug.Log("Response: " + result.Messages[^1].Content);
50+
```
51+
52+
The method returns a [`ChatInferenceResult`](~/api/Uralstech.UAI.Abstraction.Chat.ChatInferenceResult.yml)
53+
object with the generated messages, including function calls and responses. The model's plain-text response
54+
will likely be the last message in the array.
55+
56+
If you don't provide a model to use, it uses the model defined in the client's
57+
[`DefaultModelId`](~/api/Uralstech.UAI.Abstraction.IModelClient.yml#Uralstech_UAI_Abstraction_IModelClient_DefaultModelId).
58+
You can change this by either changing the default model, or by providing the model ID in the method's `model` parameter.
59+
60+
For clients that support the feature, you can also turn of the safety filters of the model by setting `tryRemoveFilters` to `true`.
61+
62+
## Function Calling
63+
64+
You can define functions using the [`Function`](~/api/Uralstech.UAI.Abstraction.Tools.Function.yml) class.
65+
They can then be passed into a [variant of the `Chat` function](~/api/Uralstech.UAI.Abstraction.IModelClient.yml#Uralstech_UAI_Abstraction_IModelClient_Chat_System_Collections_Generic_IReadOnlyList_Uralstech_UAI_Abstraction_Message__System_Collections_Generic_IReadOnlyList_Uralstech_UAI_Abstraction_Tools_Function__System_String_System_Int32_System_Boolean_System_Threading_CancellationToken_)
66+
to be called by the model.
67+
68+
```csharp
69+
using Uralstech.UAI.Abstraction.Tools;
70+
71+
ChatInferenceResult result = await client.Chat(new Message[]
72+
{
73+
new Message(Role.System, "You are a helpful, friendly assistant."),
74+
new Message(Role.User, "Can you print \"Hello, World\" to the console?")
75+
},
76+
new Function[]
77+
{
78+
new Function(
79+
nameof(PrintToConsole),
80+
"Prints text to the console.",
81+
new Parameter[]
82+
{
83+
new Parameter()
84+
{
85+
Name = "text",
86+
Description = "The text to print.",
87+
Type = ParameterType.String,
88+
}
89+
},
90+
PrintToConsole
91+
)
92+
});
93+
94+
Debug.Log("Response: " + result.Messages[^1].Content);
95+
96+
async Awaitable<JObject> PrintToConsole(JToken input)
97+
{
98+
await Awaitable.MainThreadAsync(); // Just to make this a valid Awaitable.
99+
100+
Debug.Log(input["query"].ToObject<string>());
101+
return new JObject()
102+
{
103+
["status"] = "Printed text to console."
104+
};
105+
}
106+
```

Documentation/docfx.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
{
44
"src": [
55
{
6-
"src": "../PackageName",
6+
"src": "../UAI.Abstraction",
77
"files": [
8-
"Packages/com.uralstech.package-name/Runtime/**/*.cs"
8+
"Packages/com.uralstech.uai.abstraction/Runtime/**/*.cs"
99
]
1010
}
1111
],
12+
"properties": {
13+
"DefineConstants": "COM_URALSTECH_UGEMINI;COM_OPENAI_UNITY"
14+
},
1215
"dest": "api",
1316
"filter": "filterConfig.yml",
14-
"includePrivateMembers": true,
17+
"includePrivateMembers": false,
1518
"allowCompilationErrors": true
1619
}
1720
],
@@ -39,9 +42,9 @@
3942
"modern"
4043
],
4144
"globalMetadata": {
42-
"_appName": "PackageName",
43-
"_appTitle": "PackageName",
44-
"_appFooter": "(C) 2024 URAV ADVANCED LEARNING SYSTEMS PRIVATE LIMITED, licensed under the <a href=\"https://github.com/Uralstech/PackageName/blob/master/LICENSE\">Apache License, Version 2.0</a>.",
45+
"_appName": "UAI.Abstraction",
46+
"_appTitle": "UAI.Abstraction",
47+
"_appFooter": "(C) 2024 URAV ADVANCED LEARNING SYSTEMS PRIVATE LIMITED, licensed under the <a href=\"https://github.com/Uralstech/UAI.Abstraction/blob/master/LICENSE\">Apache License, Version 2.0</a>.",
4548
"_enableSearch": true
4649
},
4750
"fileMetadata": {
@@ -59,7 +62,7 @@
5962
}
6063
},
6164
"sitemap": {
62-
"baseUrl": "https://uralstech.github.io/PackageName",
65+
"baseUrl": "https://uralstech.github.io/UAI.Abstraction",
6366
"priority": 1.0,
6467
"changefreq": "monthly"
6568
}

Documentation/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
_layout: landing
33
---
44

5-
# PackageName
5+
# UAI.Abstraction
66

7-
PackageDesc
7+
Contains abstraction for common AI APIs so that different LLM providers like Gemini and OpenAI can be used through a unified interface. Currently supports the Google Gemini and OpenAI GPT APIs.
88

9-
[![openupm](https://img.shields.io/npm/v/com.uralstech.package-name?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.uralstech.package-name/)
10-
[![openupm](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=downloads&query=%24.downloads&suffix=%2Fmonth&url=https%3A%2F%2Fpackage.openupm.com%2Fdownloads%2Fpoint%2Flast-month%2Fcom.uralstech.package-name)](https://openupm.com/packages/com.uralstech.package-name/)
9+
[![openupm](https://img.shields.io/npm/v/com.uralstech.uai.abstraction?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.uralstech.uai.abstraction/)
10+
[![openupm](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=downloads&query=%24.downloads&suffix=%2Fmonth&url=https%3A%2F%2Fpackage.openupm.com%2Fdownloads%2Fpoint%2Flast-month%2Fcom.uralstech.uai.abstraction)](https://openupm.com/packages/com.uralstech.uai.abstraction/)
1111

1212
## Installation
1313

14-
This *should* work on any reasonably modern Unity version. Built and tested in Unity 6.0.
14+
Requires Unity 6.0 because of the plugin's usage of [*Awaitable*](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.html). Built and tested in Unity 6.0.
1515

1616
# [OpenUPM](#tab/openupm)
1717

@@ -24,19 +24,19 @@ This *should* work on any reasonably modern Unity version. Built and tested in U
2424
- `com.uralstech`
2525
4. Open the Unity Package Manager window (`Window` -> `Package Manager`)
2626
5. Change the registry from `Unity` to `My Registries`
27-
6. Add the `PackageName` package
27+
6. Add the `UAI.Abstraction` package
2828

2929
# [Unity Package Manager](#tab/upm)
3030

3131
1. Open the Unity Package Manager window (`Window` -> `Package Manager`)
3232
2. Select the `+` icon and `Add package from git URL...`
3333
3. Paste the UPM branch URL and press enter:
34-
- `https://github.com/Uralstech/PackageName.git#upm`
34+
- `https://github.com/Uralstech/UAI.Abstraction.git#upm`
3535

3636
# [GitHub Clone](#tab/github)
3737

3838
1. Clone or download the repository from the desired branch (master, preview/unstable)
39-
2. Drag the package folder `PackageName/PackageName/Packages/com.uralstech.package-name` into your Unity project's `Packages` folder
39+
2. Drag the package folder `UAI.Abstraction/UAI.Abstraction/Packages/com.uralstech.uai.abstraction` into your Unity project's `Packages` folder
4040

4141
---
4242

@@ -46,4 +46,4 @@ Do not use preview versions (i.e. versions that end with "-preview") for product
4646

4747
## Documentation
4848

49-
See <https://uralstech.github.io/PackageName/DocSource/QuickStart.html> or `APIReferenceManual.pdf` and `Documentation.pdf` in the package documentation for the reference manual and tutorial.
49+
See <https://uralstech.github.io/UAI.Abstraction/DocSource/QuickStart.html> or `APIReferenceManual.pdf` and `Documentation.pdf` in the package documentation for the reference manual and tutorial.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright (C) 2024 URAV ADVANCED LEARNING SYSTEMS PRIVATE LIMITED
189+
Copyright [yyyy] [name of copyright owner]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

PackageName/Packages/com.uralstech.package-name/Runtime/PackageName.asmdef

Lines changed: 0 additions & 14 deletions
This file was deleted.

PackageName/Packages/com.uralstech.package-name/package.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

PackageName/Packages/manifest.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

PackageName/Packages/packages-lock.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

PackageName/ProjectSettings/ProjectVersion.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)