0% found this document useful (0 votes)
3 views5 pages

Get Intent

The document outlines two intents related to issue and project management, detailing nodes that define API calls and report configurations for retrieving project and issue data. Each intent includes links between nodes to facilitate data flow, with specified API endpoints for fetching project lists and issue details. Additionally, it includes Python code for intent matching using a Sentence Transformer model, which processes input questions and calculates similarity to known intents.

Uploaded by

sundar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Get Intent

The document outlines two intents related to issue and project management, detailing nodes that define API calls and report configurations for retrieving project and issue data. Each intent includes links between nodes to facilitate data flow, with specified API endpoints for fetching project lists and issue details. Additionally, it includes Python code for intent matching using a Sentence Transformer model, which processes input questions and calculates similarity to known intents.

Uploaded by

sundar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

{

"intent": "issuelist",
"question": "issue list",
"score": 0.9,
"nodes": [
{
"id": "1",
"label": "Node 1",
"x": -4.625,
"y": 62.296875,
"config": {
"responseType": "api",
"text": "",
"value": {
"apiUrl": "http://127.0.0.1:8000/jira/projects",
"apiMethod": "GET",
"apiHeaders": "",
"apiBody": ""
}
}
},
{
"id": "2",
"label": "Node 2",
"x": 91.375,
"y": 201.296875,
"config": {
"responseType": "report",
"text": "",
"value": {
"title": "Projects",
"datafield": "{{issuelist#1}}",
"summary": "List of Projects",
"columns": [
{
"key": "value[0].name",
"label": "name"
}
]
}
}
}
],
"links": [
{
"from": "1",
"to": "2"
}
]
},
{
"intent": "projects",
"question": "show projects",
"score": 1.5,
"nodes": [
{
"id": "1",
"label": "Node 1",
"x": 89.75,
"y": 98.203125,
"config": {
"responseType": "api",
"text": "",
"value": {
"apiUrl": "http://127.0.0.1:8000/jira/projects",
"apiMethod": "GET",
"apiHeaders": "",
"apiBody": ""
}
}
},
{
"id": "2",
"label": "Node 2",
"x": 94.75,
"y": 205.203125,
"config": {
"responseType": "form",
"text": "",
"value": [
{
"label": "Project",
"type": "dropdown",
"required": false,
"options": "",
"optionsType": "dynamic",
"datafield": "{{projects#1}}.value",
"datakey": "key",
"datalabel": "name"
}
]
}
},
{
"id": "3",
"label": "Node 3",
"x": 95.75,
"y": 299.203125,
"config": {
"responseType": "api",
"text": "",
"value": {
"apiUrl": "http://127.0.0.1:8000/jira/search_issues?
jql=project='{{projects#2}}.Project'",
"apiMethod": "GET",
"apiHeaders": "",
"apiBody": ""
}
}
},
{
"id": "4",
"label": "Node 4",
"x": 93.75,
"y": 408.203125,
"config": {
"responseType": "report",
"text": "",
"value": {
"title": "Issues",
"datafield": "{{projects#3}}.value.issues",
"summary": "Issuelist",
"columns": [
{
"key": "key",
"label": "Task ID"
},
{
"key": "fields.summary",
"label": "Task Summary"
},
{
"key": "fields.description",
"label": "Description"
},
{
"key": "fields.assignee.displayName",
"label": "Assignee"
},
{
"key": "fields.status.name",
"label": "Status"
},
{
"key": "fields.priority.name",
"label": "Priority"
},
{
"key": "fields.duedate",
"label": "Due Date"
},
{
"key": "fields.created",
"label": "Created Date"
},
{
"key": "fields.resolutiondate",
"label": "Resolved Date"
},
{
"key": "fields.timespent",
"label": "Time Spent"
},
{
"key": "fields.issuetype.name",
"label": "Issue Type"
}
]
}
}
}
],
"links": [
{
"from": "1",
"to": "2"
},
{
"from": "2",
"to": "3"
},
{
"from": "3",
"to": "4"
}
]
},

import nltk
from sentence_transformers import SentenceTransformer, util
import numpy as np

nltk.download('stopwords')
from nltk.corpus import stopwords

# Assuming you already have a Sentence Transformer model loaded


model = SentenceTransformer('all-mpnet-base-v2')

# Preprocessing function (as discussed in previous responses)


def preprocess_text(text):
return text
# Lowercase the text
text = text.lower()

# Remove special characters or digits (optional, depending on your needs)


text = re.sub(r'\W+', ' ', text)

# Remove stopwords (common words like "is", "the", "and", etc.)


stop_words = set(stopwords.words('english'))
text = ' '.join([word for word in text.split() if word not in stop_words])
print(text)
return text

# Intent matching function with vectorized similarity calculation


def getIntent( index,question):
db_data = db.load_db()

# Flatten all nodes from all workflows


#
intents =db_data['workflows']
processed_question = preprocess_text(question)
input_embedding = model.encode(processed_question, convert_to_tensor=True)

processed_intents = [preprocess_text(intent) for intent in intents]


intent_embeddings = model.encode(processed_intents, convert_to_tensor=True)

similarities = util.pytorch_cos_sim(input_embedding,
intent_embeddings).squeeze(0)
best_idx = torch.argmax(similarities).item()
best_intent = intents[best_idx]

print(f"Matched Intent: {best_intent}")


return best_intent
def getIntent1(index,question):
global model
# Input question

# Encode input and known questions


input_embedding = model.encode(question, convert_to_tensor=True)
best_intent = None
best_score = 0
db_data = db.load_db()

# Flatten all nodes from all workflows


#
intents =db_data['workflows'] #[node for workflow in db_data['workflows'] for
node in workflow["nodes"] if node["id"] == "1"]
for intent in intents:
#print(intent)
#print(intent["question"])

#print(intent["score"])
intent_embedding = model.encode(intent["question"], convert_to_tensor=True)
similarity = util.pytorch_cos_sim(input_embedding, intent_embedding).item()
#print(similarity)
if similarity >= intent["score"] and similarity > best_score:
best_score = similarity
best_intent = intent["intent"]
return intent

print("Matched Intent:", best_intent if best_intent else "No matching intent")

You might also like