Skip to content

Commit

Permalink
Merge pull request #116 from Azure-Samples/gk/generative-usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
thegovind authored Jul 13, 2023
2 parents 4b6f57c + 6a2e1bc commit b61fdd6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ This will be similar to [reddog](https://reddog-solutions.com) product [image ge

## Tech Stack

<TODO>
### Copilot Stack

![copilot stack](./assets/images/copilot-stack.png)

### Services and capabilities

- [Azure OpenAI](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/models)
- gpt-4
Expand Down
Binary file added assets/images/copilot-stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 75 additions & 15 deletions usecases/generative/sk-c#/sql-code-gen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
Expand All @@ -91,12 +91,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3. Create a Semantic Function (Prompt Template) and execute an ask with LLM"
"#### 3. Create a Semantic Function (Prompt Template) with a one-shot example"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 3,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
Expand All @@ -110,7 +110,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Most expensive purchase in the last year\r\n"
"{\"Name\":\"funcb9320cfb40b149b292c8e62fadc275b3\",\"SkillName\":\"_GLOBAL_FUNCTIONS_\",\"Description\":\"Generic function, unknown purpose\",\"IsSemantic\":true,\"IsSensitive\":false,\"TrustServiceInstance\":{},\"RequestSettings\":{\"Temperature\":0,\"TopP\":0.5,\"PresencePenalty\":0,\"FrequencyPenalty\":0,\"MaxTokens\":200,\"StopSequences\":[],\"ResultsPerPrompt\":1,\"ChatSystemPrompt\":\"Assistant is a large language model.\",\"TokenSelectionBiases\":{}},\"Parameters\":[{\"Name\":\"input\",\"Description\":\"\",\"DefaultValue\":\"\"}]}\r\n"
]
}
],
Expand Down Expand Up @@ -145,26 +145,86 @@
"Question: {input}.\n",
"\";\n",
"\n",
"// create semantic function\n",
"var textToSQL = kernel.CreateSemanticFunction(skPrompt, maxTokens: 200, temperature: 0, topP: 0.5);\n",
"Console.WriteLine(textToSQL.ToString());"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3. Create Context variables"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"var tableInfo = @\"\n",
" Users table has columns: user_id, first_name, last_name, and email.\n",
" Transactions table has columns: transaction_id, user_id, transaction_amount, transaction_date, and transaction_type.\n",
"\";\n",
"\n",
"// create semantic function\n",
"var textToSQL = kernel.CreateSemanticFunction(skPrompt, maxTokens: 200, temperature: 0, topP: 0.5);\n",
"\n",
"// context variables\n",
"var context = kernel.CreateNewContext();\n",
"context[\"dialect\"] = \"PostgreSQL\";\n",
"context[\"tableInfo\"] = tableInfo;\n",
"// ask\n",
"context[\"tableInfo\"] = tableInfo;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4. Generate SQL from natural language"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"SQLQuery: SELECT \n",
" u.user_id,\n",
" u.first_name,\n",
" u.last_name,\n",
" MAX(t.transaction_amount) AS most_expensive_purchase\n",
" FROM \n",
" users u\n",
" JOIN \n",
" transactions t ON u.user_id = t.user_id\n",
" WHERE \n",
" t.transaction_date >= DATE_TRUNC('year', CURRENT_DATE - INTERVAL '1 year')\n",
" GROUP BY \n",
" u.user_id, u.first_name, u.last_name;\r\n"
]
}
],
"source": [
"context[\"input\"] = \"Most expensive purchase in the last year\";\n",
"\n",
"Console.WriteLine(context);\n",
"\n",
"var summary = await textToSQL.InvokeAsync(context);\n",
"\n",
"Console.WriteLine(summary);"
"var sql = await textToSQL.InvokeAsync(context);\n",
"Console.WriteLine(sql);"
]
}
],
Expand Down

0 comments on commit b61fdd6

Please sign in to comment.