Skip to content

Commit ad82b3d

Browse files
committed
Update .gif previews, allow custom system prompt and add note on expected response structure
1 parent 7c31656 commit ad82b3d

File tree

5 files changed

+59
-23
lines changed

5 files changed

+59
-23
lines changed

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
[![OpenCollective Backers](https://opencollective.com/spyder/backers/badge.svg?color=blue)](#backers)
88
[![OpenCollective Sponsors](https://opencollective.com/spyder/sponsors/badge.svg?color=blue)](#sponsors)
99

10-
----
10+
---
1111

1212
# Overview
1313

14-
1514
## Installation
1615

1716
To use this completions provider you will need to install Spyder 6 (at least 6.0.0a3)
@@ -26,8 +25,30 @@ Or from PyPI something like:
2625

2726
Also, you need to set the environment variable `OPENAI_API_KEY`. In case
2827
you are actually using the OpenAI API you can get it from [here](https://platform.openai.com/signup)
29-
but for usage with for example local LLMs (via things like [LMStudio](https://lmstudio.ai))
30-
you just need to set it with a corresponding valid value.
28+
but for usage with, for example, local LLMs (via things like [LMStudio](https://lmstudio.ai))
29+
you will need to set it with a corresponding valid value.
30+
31+
Depending on the API you are using and options to configure available, setting the
32+
following JSON schema for the model structured output could be useful:
33+
34+
```json
35+
{
36+
"$schema": "http://json-schema.org/draft-07/schema#",
37+
"title": "Generated schema for responses",
38+
"type": "object",
39+
"properties": {
40+
"suggestions": {
41+
"type": "array",
42+
"items": {
43+
"type": "string"
44+
}
45+
}
46+
},
47+
"required": [
48+
"suggestions"
49+
]
50+
}
51+
```
3152

3253
## Preview
3354

@@ -71,8 +92,7 @@ and the donations we have received from our users around the world through [Open
7192

7293
[Spyder Github](https://github.com/spyder-ide/spyder)
7394

74-
[Troubleshooting Guide and FAQ](
75-
https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ)
95+
[Troubleshooting Guide and FAQ](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ)
7696

7797
[Development Wiki](https://github.com/spyder-ide/spyder/wiki/Dev:-Index)
7898

langchain-provider-config.gif

1.01 MB
Loading

langchain-provider.gif

368 KB
Loading

langchain_provider/provider.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ class LangchainProvider(SpyderCompletionProvider):
3636
("language", "Python"),
3737
("model_name", "No model"),
3838
("api_url", "https://api.openai.com/v1"),
39+
(
40+
"template",
41+
"""You are a helpful assistant in completing following {language} code based
42+
on the previous sentence.
43+
44+
You always give {num_suggestions} suggestions.
45+
46+
Example : a=3 b=4 print
47+
AI : "suggestions": ["print(a)", "print(b)", "print(a+b)"]
48+
Example : a=3 b=4 c
49+
AI : "suggestions": ["c=a+b", "c=a-b", "c=5"]
50+
Format the output as JSON with the following key:
51+
suggestions
52+
53+
""",
54+
),
3955
]
40-
TEMPLATE_PARAM = """You are a helpful assistant in completing following {0} code based
41-
on the previous sentence.
42-
You always complete the code in same line and give {1} suggestions.
43-
Example : a=3 b=4 print
44-
AI : "suggestions": ["print(a)", "print(b)", "print(a+b)"]
45-
Example : a=3 b=4 c
46-
AI : "suggestions": ["c=a+b", "c=a-b", "c=5"]
47-
Format the output as JSON with the following key:
48-
suggestions
49-
"""
5056

5157
def __init__(self, parent, config):
5258
super().__init__(parent, config)
@@ -58,8 +64,9 @@ def __init__(self, parent, config):
5864
None,
5965
model_name=self.get_conf("model_name"),
6066
api_url=self.get_conf("api_url"),
61-
template=self.TEMPLATE_PARAM.format(
62-
self.get_conf("language"), self.get_conf("suggestions")
67+
template=self.get_conf("template").format(
68+
language=self.get_conf("language"),
69+
num_suggestions=self.get_conf("suggestions"),
6370
),
6471
)
6572

@@ -131,8 +138,9 @@ def update_langchain_configuration(self, config):
131138
self.client.update_configuration(
132139
self.get_conf("model_name"),
133140
self.get_conf("api_url"),
134-
self.TEMPLATE_PARAM.format(
135-
self.get_conf("language"), self.get_conf("suggestions")
141+
self.get_conf("template").format(
142+
language=self.get_conf("language"),
143+
num_suggestions=self.get_conf("suggestions"),
136144
),
137145
)
138146

langchain_provider/widgets/config_dialog.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
# Third party imports
1414
from qtpy.QtCore import Qt
1515
from qtpy.QtWidgets import (
16-
QLineEdit,
1716
QDialog,
1817
QDialogButtonBox,
1918
QFormLayout,
20-
QSpinBox,
2119
QHBoxLayout,
20+
QLineEdit,
21+
QSpinBox,
22+
QTextEdit,
2223
QVBoxLayout,
2324
)
2425

@@ -31,9 +32,9 @@
3132
class LangchainConfigDialog(QDialog):
3233
def __init__(self, provider, parent=None):
3334
super().__init__(parent=parent)
34-
3535
self._provider = provider
3636

37+
self.setFixedSize(600, 400)
3738
self.setAttribute(Qt.WA_DeleteOnClose)
3839
self.setWindowTitle(_("Langchain provider configuration"))
3940
self.setModal(True)
@@ -52,10 +53,16 @@ def __init__(self, provider, parent=None):
5253
self.api_url_lineedit = QLineEdit()
5354
self.api_url_lineedit.setText(provider.get_conf("api_url"))
5455

56+
template_label_text = _("System prompt:")
57+
self.template_textedit = QTextEdit()
58+
self.template_textedit.setPlainText(provider.get_conf("template"))
59+
5560
form_layout = QFormLayout()
61+
form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
5662
form_layout.addRow(suggestions_label_text, self.suggestions_spinbox)
5763
form_layout.addRow(model_label_text, self.model_lineedit)
5864
form_layout.addRow(api_url_label_text, self.api_url_lineedit)
65+
form_layout.addRow(template_label_text, self.template_textedit)
5966

6067
bbox = QDialogButtonBox(
6168
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Vertical, self
@@ -78,4 +85,5 @@ def accept(self):
7885
self._provider.set_conf("suggestions", self.suggestions_spinbox.value())
7986
self._provider.set_conf("model_name", self.model_lineedit.text())
8087
self._provider.set_conf("api_url", self.api_url_lineedit.text())
88+
self._provider.set_conf("template", self.template_textedit.toPlainText())
8189
super().accept()

0 commit comments

Comments
 (0)