Commit Graph
409 Commits
Author SHA1 Message Date
Abby Harrison 04206c67dc Python: Update Notebooks to version 0.2.6.dev0; Fix bug in 0.2.5.dev0 (#761)
### Motivation and Context
New release version 0.2.6
Fix bug in 0.2.5.dev0 pip package
Update notebooks to the latest pip package (0.2.6)

### Description of Changes
- fixed a param name error in the creation of a reference memory_record
- renamed text_service -> text_completion_service (consistency with .NET)
- renamed text_embedding_service -> text_embedding_generation_service
(consistency with .NET)
- Updated notebooks accordingly
- bumped pip versions to 0.2.6.dev0
python-0.2.6.dev
2023-05-01 17:16:01 -07:00
Christopher Highman 80ef70f92e Resolve completion failures from an unexpected exception thrown in the Qdrant Connector (#719)
### Motivation and Context
An unexpected exception is being thrown when attempting to find nearest
vectors and no vectors exist. This results in the current completion
activity to fail. An example of this behavior can be observed in the
copilot-sample-app by changing the MemoriesStore type in appsettings
from "volatile" to "qdrant". All subsequent chat completions will fail.

There are seven other API requests in this same class which all use
roughly the same conventions and handling of the HTTP request /
response. _FindNearestInCollectionAsync_ is the only one of the eight
total which doesn't explicitly check or catch to prevent an exception.
  
For more details and context, see the write-up outlined in the linked
issue: #694

### Description
Align HTTP response behavior in FindNearestInCollectionAsync to match
the consistent behavior uniformly observed for HTTP request/response
handling. This amounts to simply breaking when the response status code
is NotFound.
2023-05-01 23:20:26 +00:00
Abby Harrison 4e2d886eff Python: Proper separation of unit and integration tests (#732)
### Motivation and Context
This PR introduces the ability to run formal integration tests for
python using pytest - separated from unit tests for easier automation.

### Description
- moved `python/tests/end-to-end` directory to
`python/tests/integration`
- renamed integration tests to test_* pattern so pytest will detect them
- import `GenerationConfig` for hugging face completions - according to
logs, this is the recommended practice
2023-05-01 16:16:36 -07:00
Teresa Hoang 309840beb1 Open API GitHub Plugin Skill + Frontend Auth (MSAL + Basic / PAT) (#641)
### Motivation and Context
This PR adds:

- Swagger files detailing List and Get Pull Request(s) functions. 
- Example 22 c on how to leverage imported OpenAPI GitHub Skill
- Basic (+ User PAT) and Msal Authentication flows in Copilot chat for
connector plug-ins, sending auth data if user enables plug-in
- Parsing headers in SemanticKernelController to import respective
OpenAPI Skill if auth information is provided

### Description
![image](https://user-images.githubusercontent.com/125500434/234473631-cb01eac2-12b7-4f78-a939-bc99f70d2184.png)

![image](https://user-images.githubusercontent.com/125500434/234473648-976fa0a5-f857-4693-b72b-b2f85a4d1eee.png)

![image](https://user-images.githubusercontent.com/125500434/234473826-9d0264a8-1e4c-464e-a59f-84affa1ae99a.png)

![image](https://user-images.githubusercontent.com/125500434/234473842-1efcbf7d-4bd4-4015-b903-c13bdd173191.png)

![image](https://user-images.githubusercontent.com/125500434/235235863-1353180f-f679-4445-afaf-4b4c2154d922.png)
2023-05-01 14:59:33 -07:00
Carlos Torres 8b482243da Allow passing custom HttpClient (#743)
### Motivation and Context
My company network needs more custom set up in HttpClient to make calls,
but SK OpenAI code only allows me to pass a hander delegate factory. I
cannot use SK without more settings in HttpClient and I want to pass in
my own instances anyway so I can manage them from my application.

I think I am not the only one to need this:
 - https://github.com/microsoft/semantic-kernel/issues/527
 - https://github.com/microsoft/semantic-kernel/issues/133

See
https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines.

### Description
Changes included:
- The OpenAI and AzureOpenAI connectors take optional HttpClient? in the
constructor methods instead of IDelegatingHandlerFactory
- Note first approach was adding two new constructor methods to each
type so you could choose. But two constructors could not be there
together with optional HttpClient? in one and optional
IDelegatingHandlerFactory? in the other because it made calls ambiguous.
Then I tried making HttpClient not optional, but that made the parameter
order different because in some there are also other optional parameters
like openai `string? organization = null`. So the not optional
HttpClient would have to come BEFORE optional openai organization in one
constructor, but the optional IDelegatingHandlerFactory comes AFTER
optional openai organization in another constructor. In the end it
seemed better to just take HttpClient and do the custom client creation
in the extension methods. I hope this is okay I know it is a bigger
change than I planned.
- IDelegatingHandlerFactory is not being used as a factory in these Open
AI connector classes anyway. They use it one to create an HttpClient
instance in the constructor method anyway and never call it again so
it's just as easy to pass in the HttpClient you want.
- Updated the extension methods in `KernelConfigOpenAIExtensions` so
that they can optionally pass in a custom HttpClient and ILogger. If
null then it uses the same defaults as before.
- There was some mix use of `Logger log` and `ILogger logger` in
different places so on the parts I changed I set these all to "logger"
because it makes it more clear that it is a object and not a "log"
method. I can undo if you don't like this.
- Changed "credentials" to "credential" to match this is one
`TokenCredenial` not a credential collection. I can undo if you don't
like this.
- Made the default HttpClientHandler static and shared for new
HttpClients with `disposeHandler: false`
https://github.com/dotnet/runtime/issues/16255
 - Updated a sample Program
 - I can add more tests if required

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [X] The code builds clean without any errors or warnings
- [X] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [X] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [X] All unit tests pass, and I have added new tests where possible
- Most tests pass but it skips some because I don't have keys for all
these model types so I hope your github build will run this and double
check.
- [ ] I didn't break anyone 😄
- I changed the constructor method args in the OpenAI code, and the will
break your users that are creating these open ai classes using their
constructors directly. If the users are using the extension methods
(AddAzureOpenAI) then they should not have problems.
- If you want I can put back all of the constructor methods so they can
be created with HttpClient or IDelegatingHandlerFactory but with
parameters orders different as explained
- I don't think those classes need to be aware of
IDelegatingHandlerFactory or have it included in the constructor
methods, since the extension method or calling code can always convert
to HttpClient before calling.
2023-05-01 14:07:57 -07:00
Devis LucatoandAdrian Bonar 87968f5478 Azure Cognitive Search connector for Semantic Memory (#747)
### Motivation and Context

Azure Cognitive Search is a managed service on Azure that allows to
store data and search it using natural language.

### Description

Add a new Semantic Memory Connector leveraging Azure Cognitive Search.
Update the syntax example to show how it seamlessly provides
`ISemanticTextMemory` API without the need to use embeddings.

Co-authored-by: Adrian Bonar <[email protected]>
2023-05-01 13:23:04 -07:00
Devis Lucato 94f7bf488c New Python release version: 0.2.5 (#753) python-0.2.5.dev 2023-05-01 11:50:26 -07:00
Stephen Toub ac12a1a673 Remove ValidationException (#749)
Remove custom ValidationException in favor of using built-in .NET
exception types typically used for the same purposes.

### Description
The conditions ValidationException was used for validating are better
suited to existing .NET exception types that .NET developers expect in
those situations.

- NotNullOrWhiteSpace is represented with ArgumentException.
- Directory not found is represented with DirectoryNotFoundException
- Invalid state of an object (e.g. a field not being initialized) is
represented with InvalidOperationException

Argument validation exceptions are also usage exceptions typically not
intended to be caught. The same would go for the ValidationExceptions
that were serving the same purpose, so having a separate type identity
for those exceptions isn't desirable.
2023-05-01 11:48:16 -07:00
Devis LucatoandAdrian Bonar 826adf1a95 Fix potential multiple enumerations (#742)
There are more of these in unit tests and samples, where I think it's
not a big deal. The PR fixes code in the SDK (one false positive simply
resolved using ICollection) and code that could be copied into other
projects.

Co-authored-by: Adrian Bonar <[email protected]>
2023-05-01 17:52:37 +00:00
Devis Lucato e8dced1f7c Fix typos and code style (#741)
* Fix filename containing a space (`ApiKeyAuthenticationHandler .cs`)
* Fix typos
* Fix code style
* Add missing rule for local constants
* Add commented code to automate code style checks. These don't work
with .NET Standard 2.0, so we'll need some extra research.
* Fix one incorrect ILogger naming
* Add some TODOs about unused code
* Fix xmldocs
2023-05-01 17:45:35 +00:00
Devis LucatoandAdrian Bonar 57cbc93d05 API simplification: make AI service ID optional (#744)
### Motivation and Context

When configuring AI models (text completion, embeddings, chat, image
generation, etc) currently one has to pass a "service Id", ie assign a
name to the configuration. This allows apps to work with different
models providing the same features, e.g. working with OpenAI and Azure
OpenAI and HuggingFace at the same time.

In many scenarios though, there is only one AI model/service provider,
e.g. an app might be using just Open AI, and in this case service names
are unused.

Also, the kernel config API allows to remove AI models from the
configuration, a tentative feature that has never been used and can be
removed for now, and reintroduced if we find scenarios or get explicit
requests.

### Description

* Make the Service ID optional, making the AI configuration simpler
* Remove some unused API, reducing the complexity of kernel config

Co-authored-by: Adrian Bonar (HE/HIM) <[email protected]>
2023-05-01 17:33:29 +00:00
Aman Sachan 0c31da2f38 Jira plugin open api (#648)
### Motivation and Context
Provide an example implementation of connecting the Semantic Kernel to
external plugins following the open api schema.

### Description
Jira Open API schema usage example
Renaming the azure key vault example, so all open api skill examples are
grouped together
Prevent RestApiOperationRunner.cs from wrapping a json response into a
json object.
2023-05-01 10:14:16 -07:00
Stephen Toub d1cfd24f1d Remove duplicative extension methods on KernelPlanExtensions (#750)
These are all handled by the corresponding overload that takes an
optional CancellationToken. Their presence also means the optionality of
the tokens in the other overloads would never actually be used.
2023-05-01 16:58:29 +00:00
Adrian Bonar 835bfcf506 Trim all configuration strings (#748)
### Motivation and Context
Hard to debug errors when there are leading or trailing spaces in
configuration values.

### Description
Trim all configuration strings on startup.
2023-05-01 09:40:45 -07:00
Stephen Toub 4d4ca974c2 Clean up exposure and handling of CancellationToken (#612)
### Motivation and Context

Clean up exposure and handling of CancellationToken in public APIs.

### Description

- In public API, they should always be the last parameter (unless they
can't be, e.g. due to a params array), named "cancellationToken", and be
non-nullable.
- Ensure they're forwarded appropriately from one API to the next. There
may be some more missing cases, but I fixed all the ones I found.
- Make the XML docs consistent.
- Remove unnecessary cancellation-related analyzer suppressions
2023-04-30 23:25:49 -07:00
poweihuang0817andPo-Wei Huang 89e3dd6790 Fix documentation link CONTRIBUTING.md (#746)
Co-authored-by: Po-Wei Huang <[email protected]>
2023-04-30 22:38:23 -07:00
Kim b911d38a81 Fix typo (#739)
Simple typo fix
2023-04-30 19:27:03 +00:00
Stephen Toub a997257329 Replace a few Regex static method calls (#728)
### Motivation and Context

Avoid use of Regex's static methods.

### Description

The static methods on Regex are convenient, but they're also a bit of a
performance trap. Parsing regexes is fairly expensive, so that static
methods employ a MRU cache to avoid reparsing on every use, but a) that
cache has cost to access and b) the cache is very small by default. The
net result is usage of other static Regex methods elsewhere in the app
can make the use of the static methods in SK much more expensive. Regex
is thread-safe, and it's better to just store the necessary instances
into readonly static fields and then use the instance methods on those.

Note that there is an analyzer that flags these, but it's only available
when targeting .NET 7+, where it recommends (and provides a fixer) for
turning them into source-generated regexes using [GeneratedRegex(...)].
2023-04-30 19:24:31 +00:00
Devis LucatoandScott Kane 8c2e8fd573 Add support for Google searches using Google.Apis.CustomSearchAPI.v1 (#737)
[see #537 - PR rebuilt to fix nuget dependency and merge conflicts]

### Motivation and Context
Allow the usage of Google search equivalent to current Bing search
implementation.


### Description
Uses the Google.Apis.CustomSearchAPI.v1 packages to interface with the
Google search API, this requires an API key from GCP and a custom search
engine ID

---------

Co-authored-by: Scott Kane <[email protected]>
2023-04-28 23:56:41 -07:00
Tao Chen 3362c20a3b Copilot chat: refactor chat history (#682)
### Motivation and Context
The chat history skill handles the creation of new chat sessions,
retrieval of chat sessions and messages, and editing of chat titles. It
was unnecessary and improper to use a skill to handle non-AI related
task.

### Description
Replace the chat history skill with a controller that provides APIs to
handle the above-mentioned tasks.
2023-04-28 16:01:09 -07:00
Abby Harrison b6db9a2353 Python SK: Simplify memory_store_base (#684)
### Motivation and Context
This PR significantly reduces the complexity of implementing a new
memory store. Previously, memory stores needed to implement
EmbeddingIndexBase, DataStoreBase, and MemoryStoreBase. Now, memory
stores only need to implement MemoryStoreBase. This PR also brings
MemoryStoreBase to parity with the .NET IMemoryStore interface.


### Description
- Removed `data_entry.py`, `data_store_base.py`,
`volatile_data_store.py`, and `embedding_index_base.py`
- Added `with_embedding` parameter to all get/search methods. Passing
the embedding between the application and storage is not optional and
defaults to False
- `MemoryStoreBase` (Python SK) == `IMemoryStore` (.NET SK)
- Updated `volatile_memory_store` to implement `MemoryStoreBase`
- Removed `ABC` from `MemoryStoreBase` 
- Added documentation to memory files

Closes https://github.com/microsoft/semantic-kernel/issues/670
2023-04-28 11:09:40 -07:00
Devis Lucato ba70843a03 Show how to render prompts (#718)
### Motivation and Context

New code example showing how to render prompts, e.g. in cases where one
wants to leverage semantic functions but execute them with a custom
flow, e.g. passing prompts to GPT Turbo 3.5.

The example shows the basics of how one could add a chat UI into an app,
selecting some piece of content, and asking AI to extract data. In this
case, instead of calling a semantic function, the code calls a Chat
model directly, to leverage chat model protections against prompt
injection.

### Description

* New syntax example, explaining how to use `PromptTemplateEngine`
* Make one chat service param optional, to simplify the code
2023-04-28 17:39:06 +00:00
Lee Miller c4e1449c4f Improve labeler rules for kernel label (#724)
### Motivation and Context
#710 tried to enable the `kernel` tag but accidentally applied to too
many changes.

### Description
The best way to resolve this was specify directories under `dotnet` to
be considered for `kernel`.
 
 https://github.com/lemillermicrosoft/semantic-kernel/pull/7
 https://github.com/lemillermicrosoft/semantic-kernel/pull/8
 https://github.com/lemillermicrosoft/semantic-kernel/pull/10
https://github.com/lemillermicrosoft/semantic-kernel/pull/9 This one was
missed before.
2023-04-28 08:05:18 -07:00
Alex ChaoandAbby Harrison f4758ff50d Fix Notebook 04 for invoke_async with context variables (#672)
### Motivation and Context
New Python API changes the signature for invoke_async.

This aligns it and makes it clearer that the context passed into
invoke_async are context variables.

This fixes the current issue where the chat function will just repeat
back the user input instead of actually chatting

---------

Co-authored-by: Abby Harrison <[email protected]>
2023-04-28 14:32:29 +00:00
Stephen Toub 7c9a46238a Add unit tests for core exception types (#723)
### Motivation and Context

Fill unit test gaps.

### Description

Simple unit tests for the core exception types.
2023-04-28 07:29:11 -07:00
Lee Miller e74274e1ee 🛠️Fix a bug in AIException constructor (#717)
The AIException constructor that takes an errorCode, a message, and a
detail was incorrectly passing null as the detail parameter to the base
constructor. This commit fixes this bug by passing the detail parameter
correctly. This ensures that the detail information is preserved and
available for error handling.

### Motivation and Context
Bug Introduced: #701
Bug Hidden by: #596
2023-04-28 06:47:05 -07:00
Lee Miller 5f53792076 🧪Re-enable Integration Tests (#716)
### Motivation and Context
Integration tests have stopped running due to #596 

### Description
This updates the yml to properly include any projects of the form
`*IntegrationTests.csproj`

There are failing tests due to changes recently that were not caught.
Will fix those separately.
2023-04-28 06:42:28 -07:00
Teresa Hoang 1dcb706be9 Fix main view height overflow issue (#702)
Fixes scrollbar issue on main view (would show a double scrollbar on
zoom. now scroll only shows on chat history component and conversations
as necessary)
2023-04-27 21:34:24 -07:00
Tao Chen 16024e7d23 Copilot chat: Document import supports pdf (#700)
Currently the document import feature only supports .txt files. We would
like to support PDF files as well.

### Description
1. Add PdfPig 0.1.8 to the project as the lib to read PDFs.
2. Update READMEs.
2023-04-27 21:17:53 -07:00
Dustin Frenton 51f77ca9a7 Grammar Only Correction (#715)
grammar changed from "Let's now revisit the our chat sample from the" to
"Let's now revisit our chat sample from the"
2023-04-27 21:14:05 -07:00
Lee Miller 097381ce67 Validate goal and handle plan parsing errors in SequentialPlanner (#707)
Added a check for empty goal in CreatePlanAsync method and threw a
PlanningException with appropriate error code. Wrapped the plan parsing
logic in a try-catch block and re-threw any exceptions as
PlanningExceptions with a different error code. This improves the
robustness and usability of the SequentialPlanner class.
2023-04-27 20:51:15 -07:00
Shawn Callegari 247dc33a08 Update dotnet-format.yml 2023-04-27 20:27:15 -07:00
Devis Lucato d9a41ef7b7 Fix code style (#714) 2023-04-27 20:20:32 -07:00
Shawn Callegari 139b5faa2d Update dotnet-format.yml 2023-04-27 20:19:58 -07:00
Shawn Callegari 609d259664 Update dotnet-format.yml 2023-04-27 20:07:27 -07:00
Shawn Callegari 2a149e236e Update dotnet-format.yml 2023-04-27 19:51:14 -07:00
Shawn Callegari aa8c268c3c Update dotnet-format.yml 2023-04-27 19:22:04 -07:00
Shawn Callegari 5a643a458d Update dotnet-format.yml 2023-04-27 19:17:49 -07:00
Adrian Bonar 384f5beae2 CopilotChat: Refactor planner to support more dynamic skill imports. (#712) 2023-04-27 19:08:40 -07:00
Shawn Callegari 8d47213f58 Update dotnet-format.yml 2023-04-27 18:51:28 -07:00
Lee Miller e456d841b0 Simplify labeler rules for kernel label (#710)
This commit simplifies the labeler rules for the kernel label by using
the any and all operators instead of a list of patterns. This makes the
rules more readable and easier to maintain and ensures `kernel` label is
used as appropriate. The logic of the rules still exclude the
SemanticKernel and SemanticKernel.Abstractions projects from the kernel
label but will now include if only non-core kernel changes are made.
2023-04-28 01:26:44 +00:00
Gil LaHaye 7af1b96b16 Add Appinsights support in Copilot Chat (#709)
### Motivation and Context
It is desired to monitor deployments of the Copilot Chat.

### Description
Add Application Insights telemetry and logging
2023-04-28 01:15:26 +00:00
Adrian Bonar 970dfa35cf CopilotChat: Update yarn.lock (#708)
Updating to proper format and content.
2023-04-28 00:47:43 +00:00
Adrian Bonar fdc348dbaf CopilotChat Disable planner by default while we stabilize (#706)
### Motivation and Context
Planner behavior is inconsistent for some scenarios.

### Description
- Disabling the feature by default in appsettings.
2023-04-27 23:49:22 +00:00
Shawn Callegari a45d374be9 Update compliance.yml for Azure Pipelines 2023-04-27 15:27:55 -07:00
SergeyMenshykh e0a439decd Support complex payload for OpenAPI skills (#680)
### Motivation and Context

This PR changes the way payload/body for POST and PUT operations is
resolved.

This change is required to support the following scenarios:
- A POST/PUT operation payload has more than one property with the same
name - { 'sender': { '**name**': 'val1'}, 'receiver': {'**name**':
'val2'} }
- A POST/PUT operation payload has a property of array of objects with
the same name - { 'receivers': [ {'**name**':'val1'},
{'**name**':'val2'} ] }
- A POST/PUT operation payload metadata is missing.

### Description
Curent RestApi functionality builds operation payload dynamically and
relies on:
- Payload metadata that describes the payload/body schema/shape and
usually obtained from OpenAPI documents.
- Arguments resolution mechanism that resolves payload parameters in SK
context.

As practice shows, in some cases (malformed OpenAPI document), the
payload metadata is missing which means that it's not possible to create
operation payload dynamically and as a result it's not possible to run
the operation. In other cases, if a payload has two of more parameters
with the same name or parameters of array type with object items it is
impossible to resolve them from SK context.

To support these scenarios, the RestApi functionality does not build the
payload dynamically anymore and instead relies on either AI or a caller
of the APi to create/supply it. To help AI generate the payload, a new
schema property will be added to the ParameterView class to describe the
payload structure/shape to AI.
2023-04-27 22:23:30 +00:00
Stephen Toub 7e30a4e06f Throw ArgumentNullExceptions for null arguments (#570)
### Motivation and Context

Use ArgumentNullException as devs expect, and avoid exception-related
work when not throwing.

### Description

.NET developers expect that passing null erroneously to a method will
result in an ArgumentNullException, but currently it's resulting in a
custom ValidationException.

There are also places where string interpolation is being used to create
the error message; the work and allocation associated with that
interpolation is going to happen regardless of whether the exception is
thrown or not.
2023-04-27 15:12:23 -07:00
Stephen Toub de0079740a Make Exception<T> base class non-generic and clean up derived types (#701)
### Motivation and Context

Fixes https://github.com/microsoft/semantic-kernel/issues/573

### Description

- Make the base class non-generic and rename it to SKException
- Remove unnecessary private ctors from derived types
- Clean up how messages are generated
2023-04-27 19:31:52 +00:00
Stephen Toub 31de013c37 Fix two build warnings (#703)
### Motivation and Context

Fix two analyzer warnings issued during the build.
2023-04-27 11:54:11 -07:00
Adrian Bonar 602d731fb5 Qdrant: don't throw on 404 when getting nearest match (#698)
### Motivation and Context
Qdrant was failing in CopilotChat on first use when querying for vectors
in collections that don't exist yet.

### Description
- Swallow 404s from Qdrant when querying for nearest match.
2023-04-27 09:46:53 -07:00