Skip to content

armgit / txtai

Public Imported from GitHub
0

πŸ’‘ All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Update notebook

davidmezzetti92d038c598d9
diff --git a/examples/08_API_Gallery.ipynb b/examples/08_API_Gallery.ipynb
index 110edf71..59a05d85 100644
--- a/examples/08_API_Gallery.ipynb
+++ b/examples/08_API_Gallery.ipynb
@@ -46,7 +46,7 @@
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai"
],
- "execution_count": null,
+ "execution_count": 1,
"outputs": []
},
{
@@ -106,7 +106,7 @@
"# Create labels model\n",
"labels = Labels()"
],
- "execution_count": null,
+ "execution_count": 2,
"outputs": []
},
{
@@ -126,7 +126,7 @@
"height": 324
},
"id": "-K2YJJzsVtfq",
- "outputId": "8f740a3a-c380-474a-f1aa-8c26adfb3c85"
+ "outputId": "23a50527-548e-4be0-dc0b-12de7981c8f7"
},
"source": [
"data = [\"Wears a red suit and says ho ho\",\n",
@@ -141,7 +141,7 @@
"# Render output to table\n",
"table([(text, tags[labels(text, tags)[0][0]]) for text in data])"
],
- "execution_count": null,
+ "execution_count": 3,
"outputs": [
{
"output_type": "display_data",
@@ -201,7 +201,7 @@
"colab": {
"base_uri": "https://localhost:8080/"
},
- "outputId": "8cc1e672-00ac-4495-f2ed-d1d7ae482105"
+ "outputId": "1b3cf6a0-4c2a-4b25-f1f7-ced42ad26575"
},
"source": [
"%%writefile index.yml\n",
@@ -209,7 +209,7 @@
"# Labels settings\n",
"labels:"
],
- "execution_count": null,
+ "execution_count": 4,
"outputs": [
{
"output_type": "stream",
@@ -229,7 +229,7 @@
"!CONFIG=index.yml nohup uvicorn \"txtai.api:app\" &> api.log &\n",
"!sleep 90"
],
- "execution_count": null,
+ "execution_count": 5,
"outputs": []
},
{
@@ -258,7 +258,7 @@
"%%capture\n",
"!git clone https://github.com/neuml/txtai.js"
],
- "execution_count": null,
+ "execution_count": 6,
"outputs": []
},
{
@@ -279,7 +279,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "zJbKRTSJV-kd",
- "outputId": "46da8eb8-3c0c-42bd-a9bf-6c4af265be9f"
+ "outputId": "5f79b724-319d-4aaa-e9bd-8dc2ebfdc91f"
},
"source": [
"%%writefile txtai.js/examples/node/src/labels.js\n",
@@ -304,7 +304,7 @@
"\n",
" for (let text of data) {\n",
" let label = await labels.label(text, tags);\n",
- " label = tags[label[0][0]];\n",
+ " label = tags[label[0].id];\n",
"\n",
" console.log(sprintf(\"%-40s %s\", text, label));\n",
" }\n",
@@ -316,7 +316,7 @@
"\n",
"run();\n"
],
- "execution_count": null,
+ "execution_count": 7,
"outputs": [
{
"output_type": "stream",
@@ -350,7 +350,7 @@
"!npm install\n",
"!npm run build"
],
- "execution_count": null,
+ "execution_count": 8,
"outputs": []
},
{
@@ -360,12 +360,12 @@
"base_uri": "https://localhost:8080/"
},
"id": "ckOHNqyaeL-B",
- "outputId": "993dda3b-e7ac-4ac9-9b34-9bd4dbe6e229"
+ "outputId": "172e6658-069a-4fa1-e914-86825f0d709e"
},
"source": [
"!node dist/labels.js"
],
- "execution_count": null,
+ "execution_count": 9,
"outputs": [
{
"output_type": "stream",
@@ -402,7 +402,7 @@
"txtai.java integrates with standard Java build tools (Gradle, Maven, SBT). The following shows how to add txtai as a dependency to Gradle.\n",
"\n",
"```gradle\n",
- "implementation 'com.github.neuml:txtai.java:v1.0.0'\n",
+ "implementation 'com.github.neuml:txtai.java:v2.0.0'\n",
"```\n",
"\n",
"For this example, we'll clone the txtai.java project to import the example build configuration."
@@ -418,7 +418,7 @@
"os.chdir(\"/content\")\n",
"!git clone https://github.com/neuml/txtai.java"
],
- "execution_count": null,
+ "execution_count": 26,
"outputs": []
},
{
@@ -439,7 +439,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "v73L8Gw0p6fh",
- "outputId": "c9a7b89f-2ec2-4ccb-c64b-3dd467936fbb"
+ "outputId": "d9c1ec5a-c122-42d6-daa5-00b204d4ba10"
},
"source": [
"%%writefile txtai.java/examples/src/main/java/LabelsDemo.java\n",
@@ -447,8 +447,8 @@
"import java.util.ArrayList;\n",
"import java.util.List;\n",
"\n",
+ "import txtai.API.IndexResult;\n",
"import txtai.Labels;\n",
- "import txtai.Labels.Score;\n",
"\n",
"public class LabelsDemo {\n",
" public static void main(String[] args) {\n",
@@ -469,8 +469,8 @@
" System.out.println(new String(new char[75]).replace(\"\\0\", \"-\"));\n",
"\n",
" for (String text: data) {\n",
- " List<Score> scores = labels.label(text, tags);\n",
- " System.out.printf(\"%-40s %s%n\", text, tags.get(scores.get(0).id));\n",
+ " List<IndexResult> label = labels.label(text, tags);\n",
+ " System.out.printf(\"%-40s %s%n\", text, tags.get(label.get(0).id));\n",
" }\n",
" }\n",
" catch (Exception ex) {\n",
@@ -479,7 +479,7 @@
" }\n",
"}\n"
],
- "execution_count": null,
+ "execution_count": 27,
"outputs": [
{
"output_type": "stream",
@@ -506,13 +506,13 @@
"base_uri": "https://localhost:8080/"
},
"id": "N2Mm3Gl5sH1z",
- "outputId": "eb9b04af-7442-4290-88e9-5a8eec07f8e1"
+ "outputId": "90e8beac-2621-439c-a9c8-8b0eb7c8c38c"
},
"source": [
"os.chdir(\"txtai.java/examples\")\n",
"!../gradlew -q --console=plain labels 2> /dev/null"
],
- "execution_count": null,
+ "execution_count": 28,
"outputs": [
{
"output_type": "stream",
@@ -551,7 +551,7 @@
"\n",
"```toml\n",
"[dependencies]\n",
- "txtai = { version = \"1.0\" }\n",
+ "txtai = { version = \"2.0\" }\n",
"tokio = { version = \"0.2\", features = [\"full\"] }\n",
"```\n",
"\n",
@@ -569,7 +569,7 @@
"!apt-get install rustc\n",
"!git clone https://github.com/neuml/txtai.rs"
],
- "execution_count": null,
+ "execution_count": 13,
"outputs": []
},
{
@@ -590,7 +590,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "jjggKnKQ7jQO",
- "outputId": "d4924ae2-b8a8-45ce-9295-b2cd2d57125d"
+ "outputId": "0079bf3c-4c79-4851-9aa9-bb89791936ba"
},
"source": [
"%%writefile txtai.rs/examples/demo/src/labels.rs\n",
@@ -612,15 +612,15 @@
"\n",
" for text in data.iter() {\n",
" let tags = vec![\"πŸŽ… Santa Clause\", \"🦌 Reindeer\", \"πŸͺ Cookies\", \"πŸŽ„ Christmas Tree\", \"🎁 Gifts\", \"πŸ‘ͺ Family\"];\n",
- " let label = tags[&labels.label(text, &tags.to_vec()).await?[0].id];\n",
+ " let label = labels.label(text, &tags).await?[0].id;\n",
"\n",
- " println!(\"{:<40} {}\", text, label);\n",
+ " println!(\"{:<40} {}\", text, tags[label]);\n",
" }\n",
"\n",
" Ok(())\n",
"}"
],
- "execution_count": null,
+ "execution_count": 14,
"outputs": [
{
"output_type": "stream",
@@ -653,7 +653,7 @@
"os.chdir(\"txtai.rs/examples/demo\")\n",
"!cargo build"
],
- "execution_count": null,
+ "execution_count": 15,
"outputs": []
},
{
@@ -663,12 +663,12 @@
"base_uri": "https://localhost:8080/"
},
"id": "-_v_FbL0-yPk",
- "outputId": "5d00872d-491b-4cfc-9622-8e38ea31c3d7"
+ "outputId": "0f127255-8fa5-47ba-81e6-d8dd0d4bc828"
},
"source": [
"!cargo run labels"
],
- "execution_count": null,
+ "execution_count": 16,
"outputs": [
{
"output_type": "stream",
@@ -724,7 +724,7 @@
"!apt install golang-go\n",
"!go get \"github.com/neuml/txtai.go\""
],
- "execution_count": null,
+ "execution_count": 17,
"outputs": []
},
{
@@ -745,7 +745,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "bLBJwkN4ANpi",
- "outputId": "62c80276-678c-4e88-9637-ca2df507b176"
+ "outputId": "c4708ab2-0022-48fd-b1e4-a8264df0aeaa"
},
"source": [
"%%writefile labels.go\n",
@@ -772,13 +772,13 @@
"\tfmt.Printf(\"%-40s %s\\n\", \"Text\", \"Label\")\n",
"\tfmt.Println(strings.Repeat(\"-\", 75))\n",
"\n",
- "\tfor _, text := range sections {\n",
- "\t\tscores := labels.Label(text, tags)\n",
- "\t\tfmt.Printf(\"%-40s %s\\n\", text, tags[scores[0].Id])\n",
+ "\tfor _, text := range data {\n",
+ "\t\tlabel := labels.Label(text, tags)\n",
+ "\t\tfmt.Printf(\"%-40s %s\\n\", text, tags[label[0].Id])\n",
"\t}\n",
"}"
],
- "execution_count": null,
+ "execution_count": 29,
"outputs": [
{
"output_type": "stream",
@@ -805,12 +805,12 @@
"base_uri": "https://localhost:8080/"
},
"id": "l1xnUbtdAy0p",
- "outputId": "7f802a37-14c9-42bf-f1b9-8c539fcf58be"
+ "outputId": "e00daf17-383a-4e20-d2d7-4a39ceaf8e7b"
},
"source": [
"!go run labels.go"
],
- "execution_count": null,
+ "execution_count": 30,
"outputs": [
{
"output_type": "stream",