Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add api test script in example folder #3779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions example/ApiTest/C#/chats/1_create_chat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/chats");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("{\n \"dataset_ids\": [\"8a85ab34ad5311ef98b00242ac120003\"],\n \"name\":\"my test chat\"\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());


}
}
}
26 changes: 26 additions & 0 deletions example/ApiTest/C#/chats/2_update_chat.cs

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions example/ApiTest/C#/chats/3_list_chats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1/api/v1/chats?name=api_create_dataset&id=8a85ab34ad5311ef98b00242ac120003");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/chats/4_delete_chat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Delete, "http://127.0.0.1/api/v1/chats");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"ids\": [\"b8f7957aabd411efafbd0242ac120006\", \"b056fb6eabd811efb6000242ac120006\"]\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
25 changes: 25 additions & 0 deletions example/ApiTest/C#/chunks/1_parse_chunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/datasets/842986a8ad5711ef8b530242ac120003/chunks");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"document_ids\": [\"621eba90adf911ef8b400242ac120003\"]\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

}
}
}
25 changes: 25 additions & 0 deletions example/ApiTest/C#/chunks/2_add_chunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/datasets/842986a8ad5711ef8b530242ac120003/documents/621eba90adf911ef8b400242ac120003/chunks");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"content\": \"add some content\"\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

}
}
}
22 changes: 22 additions & 0 deletions example/ApiTest/C#/chunks/3_list_chunks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1/api/v1/datasets/8a85ab34ad5311ef98b00242ac120003/documents/501e387aadf411ef922e0242ac120003/chunks?keywords=some content");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
25 changes: 25 additions & 0 deletions example/ApiTest/C#/chunks/4_delete_chunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Delete, "http://127.0.0.1/api/v1/datasets/8a85ab34ad5311ef98b00242ac120003/documents/501e387aadf411ef922e0242ac120003/chunks");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"chunk_ids\": [\"a74cc41dd2abc8d32a24bcc370e73412\"]\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/chunks/5_update_chunks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Put, "http://127.0.0.1/api/v1/datasets/8a85ab34ad5311ef98b00242ac120003/documents/501e387aadf411ef922e0242ac120003/chunks/f4444516b61f95adfdd293173177be4a");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n { \n \"content\": \"update some content\", \n \"important_keywords\": [\"名字由来\"] \n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
25 changes: 25 additions & 0 deletions example/ApiTest/C#/chunks/6_retrieve_chunks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/retrieval");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("{\r\n \"question\": \"some questions\",\r\n \"dataset_ids\": [\"8a85ab34ad5311ef98b00242ac120003\"],\r\n \"document_ids\": [\"501e387aadf411ef922e0242ac120003\"]\r\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/converse/1_converse_chat_assistant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/chats/7896ac36aef011efa8e70242ac120003/completions");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"question\": \"你好,你是谁?\",\n \"stream\": true\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/converse/2_converse_agent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/agents/6062501eaef211ef95180242ac120003/completions");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"question\": \"你好,你是谁?\",\n \"stream\": true\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
25 changes: 25 additions & 0 deletions example/ApiTest/C#/datasets/1_create_dataset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1/api/v1/datasets");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("{\r\n \"name\": \"api_create_dataset\" ,\r\n \"language\": \"Chinese\",\r\n \"embedding_model\":\"text-embedding-v3\"\r\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

}
}
}
23 changes: 23 additions & 0 deletions example/ApiTest/C#/datasets/2_get_dataset_info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1/api/v1/datasets?name=api_create_dataset");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/datasets/3_update_dataset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Put, "http://127.0.0.1/api/v1/datasets/919f28e0ac9b11efabe50242ac120003");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("\n {\n \"name\": \"api_updated_dataset\",\n \"chunk_method\":\"manual\",\n \"embedding_model\":\"embedding-3\"\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
24 changes: 24 additions & 0 deletions example/ApiTest/C#/datasets/4_delete_dataset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RagflowAPI
{
internal class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Delete, "http://127.0.0.1/api/v1/datasets");
request.Headers.Add("Authorization", "Bearer ragflow-hjNzA4ODI4YWM5MTExZWY5YzUyMDI0Mm");
var content = new StringContent("{\n \"ids\": [\"c26b9860ad3011efa3f90242ac120003\"]\n }", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}
}
Loading