8000 ai componenst on their own branch · sathishktk/botbuilder-python@f33ac6e · GitHub
[go: up one dir, main page]

Skip to content

Commit f33ac6e

Browse files
committed
ai componenst on their own branch
1 parent bb04283 commit f33ac6e

File tree

8 files changed

+653
-0
lines changed

8 files changed

+653
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('pkg_resources').declare_namespace(__name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('pkg_resources').declare_namespace(__name__)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding=utf-8
2+
#------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
#------------------------------------------------------------------------
7+
8+
from .language_map import LanguageMap
9+
from .qna_maker import QnAMaker, QnAMakerOptions, MetaData, QueryResult, QueryResults
10+
11+
__all__ = ['LanguageMap',
12+
'QnAMaker',
13+
'QnAMakerOptions',
14+
'MetaData',
15+
'QueryResult',
16+
'QueryResults']

libraries/botbuilder-ai/microsoft/botbuilder/ai/language_map.py

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import json
2+
import asyncio
3+
import requests
4+
5+
class QnAMaker:
6+
7+
__qnaMakerServiceEndpoint = 'https://westus.api.cognitive.microsoft.com/qnamaker/v3.0/knowledgebases/'
8+
__json_mime_type = 'application/json'
9+
__api_management_header = 'Ocp-Apim-Subscription-Key'
10+
11+
def __init__(self, options, http_client):
12+
13+
self.__http_client = _http_client or False
14+
if not self.__http_client:
15+
raise TypeError('HTTP Client failed')
16+
self.__options = options or False
17+
if not self.__options:
18+
raise TypeError('Options config error')
19+
20+
self.__answerUrl = "%s%s/generateanswer" % (__qnaMakerServiceEndpoint,options.knowledge_base_id)
21+
22+
if self.__options.ScoreThreshold == 0:
23+
self.__options.ScoreThreshold = 0.3 #Note - SHOULD BE 0.3F 'FLOAT'
24+
25+
if self.__options.Top == 0:
26+
self.__options.Top = 1
27+
28+
if self.__options.StrictFilters == None:
29+
self.__options.StrictFilters = MetaData()
30+
31+
if self.__options.MetadataBoost == None:
32+
self.__options.MetadataBoost = MetaData()
33+
34+
async def get_answers(question): # HTTP call
35+
headers = {
36+
__api_management_header : self.__options.subscription_key,
37+
"Content-Type" : __json_mime_type
38+
}
39+
40+
payload = json.dumps({
41+
"question" : question
42+
})
43+
# POST request to QnA Service
44+
content = requests.post(self.__answerUrl, headers=headers, data=payload)
45+
return content.json()
46+
47+
class QnAMakerOptions:
48+
def __init__(self, subscription_key, knowledge_base_id, score_threshhold, top, strict_filters, metadata_boost):
49+
self.subscription_key = subscription_key
50+
self.knowledge_base_id = knowledge_base_id
51+
self.score_threshhold = score_threshhold
52+
self.top = top
53+
self.strict_filters = strict_filters
54+
self.metadata_boost = metadata_boost
55+
56+
class MetaData:
57+
def __init__(self, name, value):
58+
self.name = name
59+
self.value = value
60+
61+
class QueryResult:
62+
def __init__(self, questions, answer, score, metadata, source, qna_id):
63+
self.questions = questions
64+
self.answer = answer
65+
self.score = score
66+
self.metadata = metadata
67+
self.source = source
68+
self.qna_id = qna_id
69+
70+
class QueryResults:
71+
def __init__(self, answers):
72+
self.__answers = answers

libraries/botbuilder-ai/requirements.txt

Whitespace-only changes.

libraries/botbuilder-ai/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bdist_wheel]
2+
universal=0

libraries/botbuilder-ai/setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='microsoft-botbuilder-ai',
5+
version='4.0.0-a0',
6+
url='https://www.github.com/Microsoft/botbuilder-python',
7+
long_description='Cognitive services extensions for Microsoft BotBuilder.',
8+
license='MIT',
9+
author='Microsoft',
10+
author_email='bf-reports@microsoft.com',
11+
description='',
12+
packages=find_packages(),
13+
classifiers=[
14+
'Programming Language :: Python',
15+
'Intended Audience :: Bot Developers',
16+
'License :: OSI Approved :: MIT License',
17+
'Operating System :: OS Independent',
18+
'Programming Language :: Python :: 3'
19+
]
20+
)

0 commit comments

Comments
 (0)
0