Skip to content
Snippets Groups Projects
Commit 4caec890 authored by Sangamithra Panneer Selvam's avatar Sangamithra Panneer Selvam
Browse files

Grounding LargeLanguageModel with KG

parent 1f788af9
No related branches found
No related tags found
No related merge requests found
Showing
with 12191 additions and 0 deletions
cicd.ai4eu-dev.eu:7444/tutorials/groundingllms/gllmdatabroker:v1
\ No newline at end of file
FROM python:3.8
RUN apt-get update -y
RUN apt-get install -y python3-pip python3-dev
RUN pip3 install --upgrade pip
COPY requirements.txt .
RUN pip3 install -r requirements.txt
RUN mkdir /GLMMdatabroker
COPY . /GLMMdatabroker
WORKDIR /GLMMdatabroker
RUN python3 -m grpc_tools.protoc --python_out=. --proto_path=. --grpc_python_out=. GLLM_databroker.proto
EXPOSE 8061 8062
ENTRYPOINT python3 -u GLLMserver.py
\ No newline at end of file
syntax = "proto3";
message Empty {
// Empty message
}
message UserInputs {
string organization_id = 1;
string api_key = 2;
string user_query = 3;
string usecase_data = 4;
}
service Databroker {
rpc GLMMdatabroker(Empty) returns (UserInputs);
}
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: GLLM_databroker.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='GLLM_databroker.proto',
package='',
syntax='proto3',
serialized_options=None,
create_key=_descriptor._internal_create_key,
serialized_pb=b'\n\x15GLLM_databroker.proto\"\x07\n\x05\x45mpty\"`\n\nUserInputs\x12\x17\n\x0forganization_id\x18\x01 \x01(\t\x12\x0f\n\x07\x61pi_key\x18\x02 \x01(\t\x12\x12\n\nuser_query\x18\x03 \x01(\t\x12\x14\n\x0cusecase_data\x18\x04 \x01(\t23\n\nDatabroker\x12%\n\x0eGLMMdatabroker\x12\x06.Empty\x1a\x0b.UserInputsb\x06proto3'
)
_EMPTY = _descriptor.Descriptor(
name='Empty',
full_name='Empty',
filename=None,
file=DESCRIPTOR,
containing_type=None,
create_key=_descriptor._internal_create_key,
fields=[
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=25,
serialized_end=32,
)
_USERINPUTS = _descriptor.Descriptor(
name='UserInputs',
full_name='UserInputs',
filename=None,
file=DESCRIPTOR,
containing_type=None,
create_key=_descriptor._internal_create_key,
fields=[
_descriptor.FieldDescriptor(
name='organization_id', full_name='UserInputs.organization_id', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='api_key', full_name='UserInputs.api_key', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='user_query', full_name='UserInputs.user_query', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='usecase_data', full_name='UserInputs.usecase_data', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=34,
serialized_end=130,
)
DESCRIPTOR.message_types_by_name['Empty'] = _EMPTY
DESCRIPTOR.message_types_by_name['UserInputs'] = _USERINPUTS
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Empty = _reflection.GeneratedProtocolMessageType('Empty', (_message.Message,), {
'DESCRIPTOR' : _EMPTY,
'__module__' : 'GLLM_databroker_pb2'
# @@protoc_insertion_point(class_scope:Empty)
})
_sym_db.RegisterMessage(Empty)
UserInputs = _reflection.GeneratedProtocolMessageType('UserInputs', (_message.Message,), {
'DESCRIPTOR' : _USERINPUTS,
'__module__' : 'GLLM_databroker_pb2'
# @@protoc_insertion_point(class_scope:UserInputs)
})
_sym_db.RegisterMessage(UserInputs)
_DATABROKER = _descriptor.ServiceDescriptor(
name='Databroker',
full_name='Databroker',
file=DESCRIPTOR,
index=0,
serialized_options=None,
create_key=_descriptor._internal_create_key,
serialized_start=132,
serialized_end=183,
methods=[
_descriptor.MethodDescriptor(
name='GLMMdatabroker',
full_name='Databroker.GLMMdatabroker',
index=0,
containing_service=None,
input_type=_EMPTY,
output_type=_USERINPUTS,
serialized_options=None,
create_key=_descriptor._internal_create_key,
),
])
_sym_db.RegisterServiceDescriptor(_DATABROKER)
DESCRIPTOR.services_by_name['Databroker'] = _DATABROKER
# @@protoc_insertion_point(module_scope)
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import GLLM_databroker_pb2 as GLLM__databroker__pb2
class DatabrokerStub(object):
"""Missing associated documentation comment in .proto file."""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.GLMMdatabroker = channel.unary_unary(
'/Databroker/GLMMdatabroker',
request_serializer=GLLM__databroker__pb2.Empty.SerializeToString,
response_deserializer=GLLM__databroker__pb2.UserInputs.FromString,
)
class DatabrokerServicer(object):
"""Missing associated documentation comment in .proto file."""
def GLMMdatabroker(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_DatabrokerServicer_to_server(servicer, server):
rpc_method_handlers = {
'GLMMdatabroker': grpc.unary_unary_rpc_method_handler(
servicer.GLMMdatabroker,
request_deserializer=GLLM__databroker__pb2.Empty.FromString,
response_serializer=GLLM__databroker__pb2.UserInputs.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'Databroker', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
# This class is part of an EXPERIMENTAL API.
class Databroker(object):
"""Missing associated documentation comment in .proto file."""
@staticmethod
def GLMMdatabroker(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/Databroker/GLMMdatabroker',
GLLM__databroker__pb2.Empty.SerializeToString,
GLLM__databroker__pb2.UserInputs.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
import grpc
from timeit import default_timer as timer
import logging
# import the generated classes
import GLLM_databroker_pb2_grpc
import GLLM_databroker_pb2
port = 8061
def run():
print("Calling GLLM_Stub..")
with grpc.insecure_channel('localhost:{}'.format(port)) as channel:
stub = GLLM_databroker_pb2_grpc.DatabrokerStub(channel)
ui_request = GLLM_databroker_pb2.Empty()
response = stub.GLMMdatabroker(ui_request)
print("Greeter client received: ")
print(response)
if __name__ == '__main__':
logging.basicConfig()
run()
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: GLLMdatabroker.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='GLLMdatabroker.proto',
package='',
syntax='proto3',
serialized_options=None,
create_key=_descriptor._internal_create_key,
serialized_pb=b'\n\x14GLLMdatabroker.proto\"\x07\n\x05\x45mpty\"`\n\nUserInputs\x12\x17\n\x0forganization_id\x18\x01 \x01(\t\x12\x0f\n\x07\x61pi_key\x18\x02 \x01(\t\x12\x12\n\nuser_query\x18\x03 \x01(\t\x12\x14\n\x0cusecase_data\x18\x04 \x01(\t23\n\nDatabroker\x12%\n\x0eGLMMdatabroker\x12\x06.Empty\x1a\x0b.UserInputsb\x06proto3'
)
_EMPTY = _descriptor.Descriptor(
name='Empty',
full_name='Empty',
filename=None,
file=DESCRIPTOR,
containing_type=None,
create_key=_descriptor._internal_create_key,
fields=[
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=24,
serialized_end=31,
)
_USERINPUTS = _descriptor.Descriptor(
name='UserInputs',
full_name='UserInputs',
filename=None,
file=DESCRIPTOR,
containing_type=None,
create_key=_descriptor._internal_create_key,
fields=[
_descriptor.FieldDescriptor(
name='organization_id', full_name='UserInputs.organization_id', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='api_key', full_name='UserInputs.api_key', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='user_query', full_name='UserInputs.user_query', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name='usecase_data', full_name='UserInputs.usecase_data', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=33,
serialized_end=129,
)
DESCRIPTOR.message_types_by_name['Empty'] = _EMPTY
DESCRIPTOR.message_types_by_name['UserInputs'] = _USERINPUTS
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Empty = _reflection.GeneratedProtocolMessageType('Empty', (_message.Message,), {
'DESCRIPTOR' : _EMPTY,
'__module__' : 'GLLMdatabroker_pb2'
# @@protoc_insertion_point(class_scope:Empty)
})
_sym_db.RegisterMessage(Empty)
UserInputs = _reflection.GeneratedProtocolMessageType('UserInputs', (_message.Message,), {
'DESCRIPTOR' : _USERINPUTS,
'__module__' : 'GLLMdatabroker_pb2'
# @@protoc_insertion_point(class_scope:UserInputs)
})
_sym_db.RegisterMessage(UserInputs)
_DATABROKER = _descriptor.ServiceDescriptor(
name='Databroker',
full_name='Databroker',
file=DESCRIPTOR,
index=0,
serialized_options=None,
create_key=_descriptor._internal_create_key,
serialized_start=131,
serialized_end=182,
methods=[
_descriptor.MethodDescriptor(
name='GLMMdatabroker',
full_name='Databroker.GLMMdatabroker',
index=0,
containing_service=None,
input_type=_EMPTY,
output_type=_USERINPUTS,
serialized_options=None,
create_key=_descriptor._internal_create_key,
),
])
_sym_db.RegisterServiceDescriptor(_DATABROKER)
DESCRIPTOR.services_by_name['Databroker'] = _DATABROKER
# @@protoc_insertion_point(module_scope)
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import GLLMdatabroker_pb2 as GLLMdatabroker__pb2
class DatabrokerStub(object):
"""Missing associated documentation comment in .proto file."""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.GLMMdatabroker = channel.unary_unary(
'/Databroker/GLMMdatabroker',
request_serializer=GLLMdatabroker__pb2.Empty.SerializeToString,
response_deserializer=GLLMdatabroker__pb2.UserInputs.FromString,
)
class DatabrokerServicer(object):
"""Missing associated documentation comment in .proto file."""
def GLMMdatabroker(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_DatabrokerServicer_to_server(servicer, server):
rpc_method_handlers = {
'GLMMdatabroker': grpc.unary_unary_rpc_method_handler(
servicer.GLMMdatabroker,
request_deserializer=GLLMdatabroker__pb2.Empty.FromString,
response_serializer=GLLMdatabroker__pb2.UserInputs.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'Databroker', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
# This class is part of an EXPERIMENTAL API.
class Databroker(object):
"""Missing associated documentation comment in .proto file."""
@staticmethod
def GLMMdatabroker(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/Databroker/GLMMdatabroker',
GLLMdatabroker__pb2.Empty.SerializeToString,
GLLMdatabroker__pb2.UserInputs.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
from concurrent import futures
import grpc
from app import app_run, get_parameters
import sys
import threading
import GLLM_databroker_pb2
import GLLM_databroker_pb2_grpc
import openai
from openai import OpenAI
import os
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
class DatabrokerServicer(GLLM_databroker_pb2_grpc.DatabrokerServicer):
def __init__(self):
super().__init__()
self.send_data=True
def GLMMdatabroker(self, request, context):
"""
Collect the parameters.
"""
parameters = get_parameters()
print('parameters from server side:', parameters)
logger.info(f'parameters from server side:: {parameters}')
response = GLLM_databroker_pb2.UserInputs(organization_id=str(parameters[0]), api_key=str(parameters[1]),user_query=str(parameters[2]),usecase_data=str(parameters[3]))
print('Response')
print(response)
logger.info(f'response: {response}')
logger.debug(response)
if not self.send_data:
context.set_code(grpc.StatusCode.NOT_FOUND)
context.set_details("all data has been processed")
self.send_data= not self.send_data
return response
def serve(port):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
GLLM_databroker_pb2_grpc.add_DatabrokerServicer_to_server(DatabrokerServicer(), server)
server.add_insecure_port("[::]:{}".format(port))
print("Starting server. Listening on port : " + str(port))
server.start()
threading.Thread(target=app_run()).start()
server.wait_for_termination()
if __name__ == "__main__":
logging.basicConfig()
port = 8061
serve(port)
\ No newline at end of file
from flask import Flask, render_template, redirect, url_for
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms.fields import StringField, SubmitField, PasswordField
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
app = Flask(__name__)
parameters = []
port = 8062
class GllmInputForm(FlaskForm):
organization_id= PasswordField('Organisation ID')
api_key = PasswordField('Your API-Key')
user_query = StringField('Enter your question for the GPT model')
usecase_data = StringField('Submit the usecase specific data')
submit_button = SubmitField('Submit')
#GLLM_databroker_Page
@app.route('/', methods=['GET', 'POST'])
def hello():
form = GllmInputForm()
if form.validate_on_submit():
parameters.clear()
parameters.append(form.organization_id.data)
parameters.append(form.api_key.data)
parameters.append(form.user_query.data)
parameters.append(form.usecase_data.data)
logger.info('Parameters')
print(parameters)
logger.info(f'parameters from app.py: {parameters}')
return render_template("display_prediction.html")
return render_template("index.html", example_form=form)
def get_parameters():
logger.debug("Return databroker parameters")
return parameters
def app_run():
app.secret_key = 'gllm'
bootstrap = Bootstrap(app)
app.run(host="0.0.0.0", port=8062)
grpcio==1.38.0
grpcio-tools==1.38.0
grpc-interceptor
multithreading
protobuf==3.16.0
openai
python-dotenv
Bootstrap-Flask==1.5.2
Flask==1.1.2
Flask-SQLAlchemy==2.5.1
Flask-WTF==0.14.3
google==3.0.0
googleapis-common-protos==1.53.0
Jinja2==2.11.3
pandas==1.1.5
PyYAML==5.4.1
requests==2.25.1
scikit-learn==0.24.2
sklearn==0.0
SQLAlchemy==1.4.7
threadpoolctl==2.2.0
urllib3==1.26.5
Werkzeug==1.0.1
WTForms==2.3.3
MarkupSafe==1.1.1
ItsDangerous==1.1.0
Flask-Bootstrap==3.3.7.1
.grid-container {
display: grid;
grid-column-gap: 50px;
grid-row-gap: 50px;
grid-template-columns: auto auto;
padding: 10px;
}
.grid-item {
padding: 20px;
font-size: 30px;
text-align: left;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Grounding_LLMs/GLLM_Databroker/static/img/gllm_icon.png

135 KiB

Grounding_LLMs/GLLM_Databroker/static/img/gllm_logo.png

243 KiB

function loginSuccess() {
toastr.success("Redirecting you to the dashboard")
window.location.href = "/"
}
$("#login").submit(function () {
$("#button").prop("disabled", true)
$("#img").show()
event.preventDefault()
$.ajax({
url: "/checkloginpassword",
data: $(this).serialize(),
type: "POST",
success: function (response) {
$("#img").hide()
if (response === "correct") {
setTimeout(loginSuccess, 5000)
swal
.fire({
icon: "success",
title: "Login Successful",
})
.then((result) => {
window.location.href = "/"
})
} else if (response === "wrong") {
swal
.fire({
icon: "error",
title: "Login Error",
text: "Incorrect Username or password",
})
.then((result) => {
$("#button").removeAttr("disabled")
})
}
},
error: function (error) {
console.log(error)
},
})
})
$(document).ready(function(){
$('#username').change( function(e){
var username = $('#username').val();
if(username != ''){
$.ajax({
url: '/checkloginusername',
type: 'post',
data: {username: username},
success: function(response){
if (response == "No User"){
$('#uname_response').html("User does not exist").css({'color':'red', 'text-align':'right'});
$('#button').prop('disabled', true);
}else{
$('#uname_response').html("");
$('#button').removeAttr('disabled');
}
}
});
}else{
$("#uname_response").html("");
}
})
})
\ No newline at end of file
$(document).ready(function(){
$('#confirmpassword').keyup( function(e){
var password = $('#password').val();
var confirmpassword = $('#confirmpassword').val();
if(password != confirmpassword){
$('#pass_response').html("The two passwords that you entered do not match.").css({'color':'red', 'text-align':'right'});
$('#button').prop('disabled', true);
}else{
$("#pass_response").html("");
$('#button').removeAttr('disabled');
}
})
})
\ No newline at end of file
$(document).ready(function(){
$('#username').keyup( function(e){
var username = $('#username').val();
if(username != ''){
$.ajax({
url: '/checkusername',
type: 'post',
data: {username: username},
success: function(response){
if (response == "Available"){
$('#uname_response').html(response).css({'color':'blue', 'text-align':'right'});
$('#button').removeAttr('disabled');
}else{
$('#uname_response').html(response).css({'color':'red', 'text-align':'right'});
}
}
});
}else{
$("#uname_response").html("");
}
})
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment