Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
corporate-culture-qd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王立鹏
corporate-culture-qd
Commits
c795f812
Commit
c795f812
authored
Mar 31, 2026
by
lijiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: debugger
parent
0a161bc8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
5 deletions
+42
-5
index.ts
server/index.ts
+2
-2
file.ts
server/utils/file.ts
+33
-0
openai.ts
server/utils/openai.ts
+7
-3
No files found.
server/index.ts
View file @
c795f812
import
cors
from
'cors'
import
cors
from
'cors'
import
express
from
'express'
import
express
from
'express'
import
{
setAuthorization
}
from
'./utils/headers'
import
{
setAuthorization
}
from
'./utils/headers'
import
{
create
OpenAIClient
}
from
'./utils/openai'
import
{
get
OpenAIClient
}
from
'./utils/openai'
import
{
registerChatRoutes
}
from
'./route/chat'
import
{
registerChatRoutes
}
from
'./route/chat'
import
{
registerBasicRoutes
}
from
'./route/basic'
import
{
registerBasicRoutes
}
from
'./route/basic'
const
client
=
create
OpenAIClient
()
const
client
=
get
OpenAIClient
()
const
app
=
express
()
const
app
=
express
()
const
PORT
=
4000
const
PORT
=
4000
...
...
server/utils/file.ts
0 → 100644
View file @
c795f812
import
fs
from
'fs'
import
{
getOpenAIClient
}
from
'./openai'
const
openai
=
getOpenAIClient
()
export
async
function
createFile
(
filePath
:
string
)
{
let
result
if
(
filePath
.
startsWith
(
'http://'
)
||
filePath
.
startsWith
(
'https://'
))
{
// Download the file content from the URL
const
res
=
await
fetch
(
filePath
)
console
.
log
(
res
,
22
)
const
buffer
=
await
res
.
arrayBuffer
()
const
urlParts
=
filePath
.
split
(
'/'
)
const
fileName
=
urlParts
[
urlParts
.
length
-
1
]
const
file
=
new
File
([
buffer
],
fileName
)
result
=
await
openai
.
files
.
create
({
file
:
file
,
purpose
:
'assistants'
,
})
}
else
{
// Handle local file path
const
fileContent
=
fs
.
createReadStream
(
filePath
)
result
=
await
openai
.
files
.
create
({
file
:
fileContent
,
purpose
:
'assistants'
,
})
}
return
result
.
id
}
// Replace with your own file path or URL
const
fileId
=
await
createFile
(
'https://cdn.openai.com/API/docs/deep_research_blog.pdf'
)
console
.
log
(
fileId
,
11
)
server/utils/openai.ts
View file @
c795f812
import
dotenv
from
'dotenv'
import
dotenv
from
'dotenv'
import
OpenAI
from
'openai'
import
OpenAI
from
'openai'
export
function
createOpenAIClient
()
{
let
openaiClient
:
OpenAI
|
null
=
null
export
function
getOpenAIClient
()
{
if
(
openaiClient
)
return
openaiClient
// 只在这里加载 .env.local,避免启动时重复/冲突
// 只在这里加载 .env.local,避免启动时重复/冲突
dotenv
.
config
({
path
:
'.env.local'
,
override
:
true
})
dotenv
.
config
({
path
:
'.env.local'
,
override
:
true
})
...
@@ -18,6 +22,6 @@ export function createOpenAIClient() {
...
@@ -18,6 +22,6 @@ export function createOpenAIClient() {
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
return
new
OpenAI
({
apiKey
,
baseURL
})
openaiClient
=
new
OpenAI
({
apiKey
,
baseURL
})
return
openaiClient
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment