forked from overleaf/overleaf
-
Notifications
You must be signed in to change notification settings - Fork 8
copilot #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HGChuang
wants to merge
12
commits into
lcpu-club:main
Choose a base branch
from
HGChuang:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
copilot #27
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
df6ae2f
copilot
HGChuang 356ab3c
根据社区建议修改:1.精简注释,更改注释为中文。2.减少挂载数目,核心代码放在app下3.修改develop/docker-compose…
HGChuang c63628b
根据社区建议修改:1.精简注释,更改注释为中文。2.减少挂载数目,核心代码放在app下3.修改develop/docker-compose…
HGChuang 4292732
补充修改换行
HGChuang 79d2374
部分优化
HGChuang 8b7fb4f
部分优化
HGChuang bab8f5c
Delete services/web/.dockerignore
HGChuang d6cbd9c
Add .dockerignore to web service
HGChuang f8b686c
部分优化
HGChuang 0fe46b6
优化
HGChuang 2de6256
优化settings使用
HGChuang 5af7f3a
优化
HGChuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
|
||
# user defined files | ||
.env | ||
docker-compose.override.yml | ||
docker-compose.override.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,8 @@ services: | |
dockerfile: services/real-time/Dockerfile | ||
env_file: | ||
- dev.env | ||
environment: | ||
- SESSION_SECRET=helloworld | ||
|
||
redis: | ||
image: redis:5 | ||
|
@@ -140,6 +142,16 @@ services: | |
volumes: | ||
- spelling-cache:/overleaf/services/spelling/cache | ||
|
||
llm: | ||
build: | ||
context: .. | ||
dockerfile: services/llm/Dockerfile | ||
env_file: | ||
- dev.env | ||
depends_on: | ||
- mongo | ||
- redis | ||
|
||
web: | ||
build: | ||
context: .. | ||
|
@@ -153,7 +165,8 @@ services: | |
- EMAIL_CONFIRMATION_DISABLED=true | ||
- NODE_ENV=development | ||
- OVERLEAF_ALLOW_PUBLIC_ACCESS=true | ||
command: ["node", "app.js"] | ||
- SESSION_SECRET=helloworld | ||
command: ["node", "app.mjs"] | ||
volumes: | ||
- sharelatex-data:/var/lib/overleaf | ||
- web-data:/overleaf/services/web/data | ||
|
@@ -172,8 +185,10 @@ services: | |
- project-history | ||
- real-time | ||
- spelling | ||
- llm | ||
|
||
webpack: | ||
user: root | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary for this service to run? |
||
build: | ||
context: .. | ||
dockerfile: services/web/Dockerfile | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM node:20.19.5 AS base | ||
|
||
WORKDIR /overleaf/services/llm | ||
|
||
|
||
FROM base AS app | ||
|
||
COPY package.json package-lock.json /overleaf/ | ||
COPY services/llm/package.json /overleaf/services/llm/ | ||
COPY libraries/ /overleaf/libraries/ | ||
COPY patches/ /overleaf/patches/ | ||
|
||
|
||
RUN cd /overleaf && npm install | ||
|
||
COPY services/llm/ /overleaf/services/llm/ | ||
|
||
FROM app | ||
USER node | ||
CMD ["node", "--expose-gc", "app.js"] | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// src/app.js | ||
import express from 'express'; | ||
import connectDB from './config/db.js'; | ||
import keysRoutes from './app/routes/keys.routes.js'; | ||
import llmRoutes from './app/routes/llm.routes.js'; | ||
import cookieParser from 'cookie-parser'; | ||
import { PORT,LISTEN_ADDRESS} from './config/settings.defaults.cjs'; | ||
|
||
const app = express(); | ||
|
||
app.use(cookieParser()); | ||
|
||
app.use(express.json()); | ||
|
||
// connect to database | ||
await connectDB(); | ||
|
||
// register routes | ||
app.use('/api/v1/llm', keysRoutes); | ||
|
||
app.use('/api/v1/llm', llmRoutes); | ||
|
||
app.listen(PORT, LISTEN_ADDRESS, () => { | ||
console.log(`server running on ${PORT}`); | ||
}); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { KeysService } from '../services/keys.service.js'; | ||
import {getUserIdentifier} from '../utils/common.js'; | ||
export class KeysController { | ||
constructor() { | ||
this.keysService = new KeysService(); | ||
} | ||
|
||
async saveKey(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const { name, baseUrl, apiKey } = req.body; | ||
await this.keysService.saveApiKey(userIdentifier, name, baseUrl, apiKey); | ||
res.status(200).json({ success: true }); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
|
||
async deleteKey(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const { name } = req.body; | ||
const result = await this.keysService.deleteApiKey(userIdentifier, name); | ||
res.status(200).json({ success: true, data: result }); | ||
} catch (error) { | ||
console.log(error.message) | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
|
||
async getLlmInfo(req, res) { | ||
|
||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const result = await this.keysService.getLlmInfo(userIdentifier); | ||
res.status(200).json({ success: true, data: result }); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
async getUsingLlm(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const result = await this.keysService.getUsingLlm(userIdentifier); | ||
res.status(200).json({ success: true, data: result }); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
|
||
|
||
async updateUsingLlm(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const { usingLlm } = req.body; | ||
await this.keysService.updateUsingLlm(userIdentifier, usingLlm); | ||
res.status(200).json({ success: true }); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
async updateUsingModel(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
const { name, chatOrCompletion, newModel } = req.body; | ||
await this.keysService.updateUsingModel(userIdentifier, name, chatOrCompletion, newModel); | ||
res.status(200).json({ success: true }); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data: error.message }); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { LLMService } from "../services/llm.service.js"; | ||
import {getUserIdentifier} from '../utils/common.js'; | ||
export class LLMController { | ||
constructor() { | ||
this.llmService = new LLMService(); | ||
} | ||
async chat(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
// console.log('llmcontroller:',userIdentifier) | ||
|
||
const { ask, selection, filelist, outline, mode } = req.body; | ||
//console.log('llmcontroller body:',ask, selection, filelist, outline, mode) | ||
const content = await this.llmService.chat( | ||
userIdentifier, ask, selection, filelist, outline, mode | ||
); | ||
res.status(200).json({ | ||
success: true, | ||
data: content | ||
}); | ||
} catch (error) { | ||
res.status(400).json({ success: false, data:error.message }); | ||
} | ||
} | ||
/** | ||
* completion | ||
*/ | ||
async completion(req, res) { | ||
try { | ||
const sid = req.cookies['overleaf.sid']; | ||
const userIdentifier = await getUserIdentifier(sid); | ||
console.log('userIdentifier:', userIdentifier); | ||
const { cursorOffset, leftContext, rightContext, language, maxLength, fileList, outline } = req.body; | ||
|
||
const content = await this.llmService.completion( | ||
userIdentifier, cursorOffset, leftContext, rightContext, language, maxLength, fileList, outline | ||
); | ||
//const content = "helo world"; | ||
console.log('completion content:', content); | ||
res.status(200).json({ | ||
success: true, | ||
data: content | ||
}); | ||
} catch (err) { | ||
console.error('completion error:', err); | ||
res.status(400).json({ success: false, data:err.message }); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommended development environment is to use docker as defined in /develop/README.md . We can keep this .gitignore as is.